src/CmsBundle/EventListener/UserLocaleListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Session\Session;
  4. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  5. /**
  6.  * Stores the locale of the user in the session after the
  7.  * login. This can be used by the LocaleListener afterwards.
  8.  */
  9. class UserLocaleListener
  10. {
  11.     /**
  12.      * @var Session
  13.      */
  14.     private $session;
  15.     public function __construct(Session $session)
  16.     {
  17.         $this->session $session;
  18.     }
  19.     /**
  20.      * @param InteractiveLoginEvent $event
  21.      */
  22.     public function onInteractiveLogin(InteractiveLoginEvent $event)
  23.     {
  24.         $user $event->getAuthenticationToken()->getUser();
  25.         // $isAdmin = !preg_match('/(^admin_|^admin$)/', $request->get('_route'));
  26.         $session_name '_locale';
  27.         // if($isAdmin){
  28.         //     $session_name = 'admin_locale';
  29.         // }
  30.         if (null !== $user->getLocale()) {
  31.             $this->session->set($session_name$user->getLocale());
  32.         }
  33.     }
  34. }