]>
Commit | Line | Data |
---|---|---|
c89d35e8 NL |
1 | <?php |
2 | ||
535bfcbe | 3 | namespace Wallabag\CoreBundle\Event\Listener; |
c89d35e8 NL |
4 | |
5 | use Symfony\Component\HttpFoundation\Session\Session; | |
6 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | |
7 | ||
8 | /** | |
4d4147b2 JB |
9 | * Stores the locale of the user in the session after the login. |
10 | * If no locale are defined (if user doesn't change it from the login screen), override it with the user's config one. | |
11 | * | |
12 | * This can be used by the LocaleListener afterwards. | |
2aac2f27 JB |
13 | * |
14 | * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html | |
c89d35e8 NL |
15 | */ |
16 | class UserLocaleListener | |
17 | { | |
18 | /** | |
19 | * @var Session | |
20 | */ | |
21 | private $session; | |
22 | ||
23 | public function __construct(Session $session) | |
24 | { | |
25 | $this->session = $session; | |
26 | } | |
27 | ||
28 | /** | |
29 | * @param InteractiveLoginEvent $event | |
30 | */ | |
31 | public function onInteractiveLogin(InteractiveLoginEvent $event) | |
32 | { | |
33 | $user = $event->getAuthenticationToken()->getUser(); | |
34 | ||
4d4147b2 | 35 | if (null !== $user->getConfig()->getLanguage() && null === $this->session->get('_locale')) { |
c89d35e8 NL |
36 | $this->session->set('_locale', $user->getConfig()->getLanguage()); |
37 | } | |
38 | } | |
39 | } |