Update LocaleSubscriber.php

pull/3768/head
Julio Montoya 4 years ago
parent 50dcc20fc7
commit 4359c2159a
  1. 31
      src/CoreBundle/EventSubscriber/LocaleSubscriber.php
  2. 22
      src/CoreBundle/EventSubscriber/UserLocaleSubscriber.php
  3. 10
      src/CoreBundle/Resources/config/services.yml

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\EventListener;
namespace Chamilo\CoreBundle\EventSubscriber;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Manager\SettingsManager;
@ -12,26 +12,20 @@ use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Class LocaleListener
* Checks the portal listener depending of different settings:
* platform, user, course.
*/
class LocaleListener implements EventSubscriberInterface
class LocaleSubscriber implements EventSubscriberInterface
{
protected $settingsManager;
protected $defaultLocale;
protected $paremeterBag;
/**
* LocaleListener constructor.
*
* @param string $defaultLocale
*/
public function __construct($defaultLocale, SettingsManager $settingsManager, ParameterBagInterface $paremeterBag)
protected $parameterBag;
protected $settingsManager;
public function __construct(string $defaultLocale, SettingsManager $settingsManager, ParameterBagInterface $parameterBag)
{
$this->defaultLocale = $defaultLocale;
$this->settingsManager = $settingsManager;
$this->paremeterBag = $paremeterBag;
$this->parameterBag = $parameterBag;
}
public function onKernelRequest(RequestEvent $event)
@ -40,12 +34,16 @@ class LocaleListener implements EventSubscriberInterface
if (!$request->hasPreviousSession()) {
return;
}
$installed = 1 === (int) $this->paremeterBag->get('installed');
$installed = 1 === (int) $this->parameterBag->get('installed');
if (!$installed) {
return;
}
if (false === $request->hasSession()) {
return;
}
$loadFromDb = $request->getSession()->get('check_locale_from_db', true);
if (false === $loadFromDb &&
@ -142,14 +140,11 @@ class LocaleListener implements EventSubscriberInterface
}
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
// must be registered before the default Locale listener
KernelEvents::REQUEST => [['onKernelRequest', 15]],
KernelEvents::REQUEST => [['onKernelRequest', 20]],
];
}
}

@ -2,28 +2,24 @@
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\EventListener;
namespace Chamilo\CoreBundle\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
/**
* Class UserLocaleListener.
*
* Stores the locale of the user in the session after the
* login. This can be used by the LocaleListener afterwards.
* login. This can be used by the LocaleSubscriber afterwards.
*
* Priority order: platform -> user
* Priority order: platform -> user -> course
*/
class UserLocaleListener
class UserLocaleSubscriber implements EventSubscriberInterface
{
/** @var SessionInterface */
private $session;
/**
* UserLocaleListener constructor.
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
@ -35,9 +31,17 @@ class UserLocaleListener
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
if (null !== $user->getLocale()) {
$this->session->set('_locale', $user->getLocale());
$this->session->set('_locale_user', $user->getLocale());
}
}
public static function getSubscribedEvents()
{
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];
}
}

@ -152,15 +152,13 @@ services:
- {name: kernel.event_listener, event: kernel.controller, method: onKernelController}
# Locale listener
Chamilo\CoreBundle\EventListener\LocaleListener:
Chamilo\CoreBundle\EventSubscriber\LocaleSubscriber:
arguments: ['%kernel.default_locale%', '@chamilo.settings.manager', '@parameter_bag']
tags:
- {name: kernel.event_subscriber, priority: 15}
# User locale listener
Chamilo\CoreBundle\EventListener\UserLocaleListener:
tags:
- {name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin, priority: 15}
# Chamilo\CoreBundle\EventListener\UserLocaleListener:
# tags:
# - {name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin, priority: 15}
# Settings listener
Chamilo\CoreBundle\EventListener\SettingListener:

Loading…
Cancel
Save