src/EventSubscriber/LoginLocaleSubscriber.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  5. class LoginLocaleSubscriber implements EventSubscriberInterface
  6. {
  7.     public static function getSubscribedEvents()
  8.     {
  9.         return [
  10.             InteractiveLoginEvent::class => 'onLogin',
  11.         ];
  12.     }
  13.     public function onLogin(InteractiveLoginEvent $event)
  14.     {
  15.         $request $event->getRequest();
  16.         $session $request->getSession();
  17.         // si l'utilisateur a choisi une langue avant login, on la réapplique
  18.         if ($session->has('_locale')) {
  19.             $request->setLocale($session->get('_locale'));
  20.         }
  21.     }
  22. }