From 2da1d004c166cb51443fa1bf4dd91ba3668fe8c6 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 22 May 2018 09:56:42 +0200 Subject: [PATCH] Remove "lunetics/locale-bundle", fix lang switcher and listeners --- assets/js/main.js | 1 + composer.json | 3 +- config/bundles.php | 1 - config/packages/lunetics_locale.yaml | 7 -- config/services.yaml | 1 - .../EventListener/LegacyListener.php | 15 ++- .../EventListener/LegacyLoginListener.php | 3 - .../EventListener/LocaleListener.php | 11 ++- src/CoreBundle/Resources/config/services.yml | 2 +- .../views/Layout/base-layout.html.twig | 95 +++++++++---------- .../views/Sidebar/left_menu.html.twig | 2 - .../Resources/views/Sidebar/login.html.twig | 22 ++++- .../views/Sidebar/menu_knp.html.twig | 4 +- 13 files changed, 90 insertions(+), 77 deletions(-) delete mode 100644 config/packages/lunetics_locale.yaml diff --git a/assets/js/main.js b/assets/js/main.js index d5226b8481..d49b6699d4 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -27,6 +27,7 @@ require("timeago"); require("select2/dist/css/select2.css"); require('bootstrap-select/dist/js/bootstrap-select.js'); require('bootstrap-select/dist/css/bootstrap-select.css'); +require('flag-icon-css/css/flag-icon.css'); // doesn't work with webpack added directly in /public/libs folder /* diff --git a/composer.json b/composer.json index 0d646a7b45..dcf5bf2af1 100755 --- a/composer.json +++ b/composer.json @@ -127,7 +127,7 @@ "emojione/emojione": "1.3.0", - "zendframework/zend-config": "~3.0", + "zendframework/zend-config": "~3.2", "zendframework/zend-feed": "~2.9", "zendframework/zend-filter": "~2.7", "zendframework/zend-http": "~2.7", @@ -156,7 +156,6 @@ "kigkonsult/icalcreator": "2.24", "essence/essence": "~3.0", "paragonie/random-lib": "2.0.0", - "lunetics/locale-bundle": "^2.6", "hwi/oauth-bundle": "~0.6", "php-http/guzzle6-adapter": "^1.1", "php-http/httplug-bundle": "^1.8", diff --git a/config/bundles.php b/config/bundles.php index 0aa7c67567..45b361b5bb 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -57,7 +57,6 @@ return [ Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], Sylius\Bundle\SettingsBundle\SyliusSettingsBundle::class => ['all' => true], - Lunetics\LocaleBundle\LuneticsLocaleBundle::class => ['all' => true], Http\HttplugBundle\HttplugBundle::class => ['all' => true], Oneup\FlysystemBundle\OneupFlysystemBundle::class => ['all' => true], Sonata\CacheBundle\SonataCacheBundle::class => ['all' => true], diff --git a/config/packages/lunetics_locale.yaml b/config/packages/lunetics_locale.yaml deleted file mode 100644 index 8925e1116b..0000000000 --- a/config/packages/lunetics_locale.yaml +++ /dev/null @@ -1,7 +0,0 @@ -lunetics_locale: - guessing_order: - - session - - query - - router - #- browser - allowed_locales: '%locales%' diff --git a/config/services.yaml b/config/services.yaml index 4f239f03fc..8ac8fa1e4b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,7 +4,6 @@ parameters: password_encryption: '%env(APP_ENCRYPT_METHOD)%' secret: '%env(APP_SECRET)%' locale: '%env(APP_LOCALE)%' - locales: ['%env(APP_LOCALE)%'] url_append: '%env(APP_URL_APPEND)%' installed: '%env(APP_INSTALLED)%' twig: diff --git a/src/CoreBundle/EventListener/LegacyListener.php b/src/CoreBundle/EventListener/LegacyListener.php index 03c17856b2..c3acf71913 100644 --- a/src/CoreBundle/EventListener/LegacyListener.php +++ b/src/CoreBundle/EventListener/LegacyListener.php @@ -43,11 +43,10 @@ class LegacyListener $container->get('router')->getRouteCollection()->add('legacy_index', $route);*/ } - $context = $container->get('router.request_context'); + /*$context = $container->get('router.request_context'); $context->setBaseUrl('/'); - $container->get('router.default')->setContext($context); + $container->get('router.default')->setContext($context);*/ - //var_dump($container->get('router.default')->generate('home')); // Setting container Container::setContainer($container); Container::setLegacyServices($container); @@ -116,6 +115,15 @@ class LegacyListener $extraHeader = trim(api_get_setting('header_extra_content')); $container->get('twig')->addGlobal('header_extra_content', $extraHeader); + + $languages = api_get_languages(); + $languageList = []; + foreach ($languages as $isoCode => $language) { + $languageList[languageToCountryIsoCode($isoCode)] = $language; + } + + $container->get('twig')->addGlobal('current_locale_iso',languageToCountryIsoCode($request->getLocale())); + $container->get('twig')->addGlobal('available_locales', $languages); } // We set cid_reset = true if we enter inside a main/admin url @@ -125,7 +133,6 @@ class LegacyListener } else { $session->set('cid_reset', false); } - $session->set('access_url_id', $urlId); } diff --git a/src/CoreBundle/EventListener/LegacyLoginListener.php b/src/CoreBundle/EventListener/LegacyLoginListener.php index 65b4816482..21c110683e 100644 --- a/src/CoreBundle/EventListener/LegacyLoginListener.php +++ b/src/CoreBundle/EventListener/LegacyLoginListener.php @@ -52,7 +52,6 @@ class LegacyLoginListener implements EventSubscriberInterface $container = $this->container; $token = $this->tokenStorage->getToken(); - $session = $request->getSession(); if ($token) { $isGranted = $container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY'); if ($isGranted) { @@ -78,9 +77,7 @@ class LegacyLoginListener implements EventSubscriberInterface $locale = isset($languages[$user->getLanguage()]) ? $languages[$user->getLanguage()] : ''; if ($user && !empty($locale)) { $user->setLocale($locale); - //$request->getSession()->set('_locale_user', $locale); - // if no explicit locale has been set on this request, use one from the session $request->getSession()->set('_locale', $locale); $request->setLocale($locale); diff --git a/src/CoreBundle/EventListener/LocaleListener.php b/src/CoreBundle/EventListener/LocaleListener.php index 7f7ea30391..16ed97c5f0 100644 --- a/src/CoreBundle/EventListener/LocaleListener.php +++ b/src/CoreBundle/EventListener/LocaleListener.php @@ -47,13 +47,14 @@ class LocaleListener implements EventSubscriberInterface return; } - $request = $event->getRequest(); $container = $this->container; $installed = $container->get('kernel')->isInstalled(); + if (!$installed) { return; } + $request = $event->getRequest(); $courseCode = $request->get('course'); // Detect if the course was set with a cidReq: @@ -74,8 +75,6 @@ class LocaleListener implements EventSubscriberInterface if ($locale = $request->attributes->get('_locale')) { $request->getSession()->set('_locale', $locale); } else { - $locale = $this->defaultLocale; - // 1. Check platform locale /** @var SettingsManager $settings */ $settings = $this->container->get('chamilo.settings.manager'); @@ -101,6 +100,12 @@ class LocaleListener implements EventSubscriberInterface } } + // 4. force locale if it was selected from the URL + $localeFromUrl = $request->get('_locale'); + if (!empty($localeFromUrl)) { + $locale = $localeFromUrl; + } + // if no explicit locale has been set on this request, use one from the session $request->setLocale($locale); $request->getSession()->set('_locale', $locale); diff --git a/src/CoreBundle/Resources/config/services.yml b/src/CoreBundle/Resources/config/services.yml index bf436e4d52..ef87573f54 100644 --- a/src/CoreBundle/Resources/config/services.yml +++ b/src/CoreBundle/Resources/config/services.yml @@ -157,7 +157,7 @@ services: class: Chamilo\CoreBundle\EventListener\LocaleListener arguments: ['%kernel.default_locale%', '@service_container'] tags: - - {name: kernel.event_subscriber} + - {name: kernel.event_subscriber, priority: 9} # User locale listener chamilo_core.listener.user_locale_listener: diff --git a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig index 725c57a5f6..b099ed121f 100644 --- a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig +++ b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig @@ -179,62 +179,61 @@
- {#{{ locale_switcher() }}#} - {# course navigation links/shortcuts need to be activated by the admin #} {#{% include "@template_style/layout/course_navigation.html.twig" %}#} {#{% endif %}#} diff --git a/src/ThemeBundle/Resources/views/Sidebar/left_menu.html.twig b/src/ThemeBundle/Resources/views/Sidebar/left_menu.html.twig index ffaed63565..588adec748 100644 --- a/src/ThemeBundle/Resources/views/Sidebar/left_menu.html.twig +++ b/src/ThemeBundle/Resources/views/Sidebar/left_menu.html.twig @@ -38,10 +38,8 @@
{% endif %} {% endif %} - {{ macro.panel( 'Help' | trans, mopa_bootstrap_menu('ChamiloCoreBundle:LeftMenuBuilder:helpMenu', {'automenu': 'pills', 'stacked':true}) ) }} - {% endautoescape %} diff --git a/src/ThemeBundle/Resources/views/Sidebar/login.html.twig b/src/ThemeBundle/Resources/views/Sidebar/login.html.twig index 8136864cce..3dc6524c2f 100644 --- a/src/ThemeBundle/Resources/views/Sidebar/login.html.twig +++ b/src/ThemeBundle/Resources/views/Sidebar/login.html.twig @@ -1,5 +1,23 @@ -{{ locale_switcher(null, null, 'ChamiloCoreBundle:Admin:switcher_links.html.twig') }} - +
+ + +
diff --git a/src/ThemeBundle/Resources/views/Sidebar/menu_knp.html.twig b/src/ThemeBundle/Resources/views/Sidebar/menu_knp.html.twig index ed77a729de..6dde7783b7 100644 --- a/src/ThemeBundle/Resources/views/Sidebar/menu_knp.html.twig +++ b/src/ThemeBundle/Resources/views/Sidebar/menu_knp.html.twig @@ -16,9 +16,7 @@ mopa_bootstrap_menu('ChamiloCoreBundle:CourseMenuBuilder:skillsMenu', {'automenu': 'pills', 'stacked':true})) }} {% else %} - {{ locale_switcher(null, null, 'ChamiloCoreBundle:Admin:switcher_links.html.twig') }} -
- +
switcher