diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php')
-rw-r--r-- | src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php b/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php new file mode 100644 index 00000000..97bfabc8 --- /dev/null +++ b/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php | |||
@@ -0,0 +1,35 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use Symfony\Component\HttpFoundation\Session\Session; | ||
6 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | ||
7 | |||
8 | /** | ||
9 | * Stores the locale of the user in the session after the | ||
10 | * login. This can be used by the LocaleListener afterwards. | ||
11 | */ | ||
12 | class UserLocaleListener | ||
13 | { | ||
14 | /** | ||
15 | * @var Session | ||
16 | */ | ||
17 | private $session; | ||
18 | |||
19 | public function __construct(Session $session) | ||
20 | { | ||
21 | $this->session = $session; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * @param InteractiveLoginEvent $event | ||
26 | */ | ||
27 | public function onInteractiveLogin(InteractiveLoginEvent $event) | ||
28 | { | ||
29 | $user = $event->getAuthenticationToken()->getUser(); | ||
30 | |||
31 | if (null !== $user->getConfig()->getLanguage()) { | ||
32 | $this->session->set('_locale', $user->getConfig()->getLanguage()); | ||
33 | } | ||
34 | } | ||
35 | } | ||