aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2018-10-15 08:31:42 +0000
committerGitHub <noreply@github.com>2018-10-15 08:31:42 +0000
commit5bb01c034424b56a0a0ae4bc34ae5bb9a514deba (patch)
treebb18d67c8ec03bf8abd24dc6ef2138c3f81f6fa5 /src/Wallabag/CoreBundle
parent43b6f3a8a8173c47475632ca2869f190b552b5d6 (diff)
parent4d4147b228ac90f329fd2d40dd4fb60cb980328a (diff)
downloadwallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.tar.gz
wallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.tar.zst
wallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.zip
Merge pull request #3216 from wallabag/change-locale-register
Added possibility to change locale from login/register pages
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php22
-rw-r--r--src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php8
2 files changed, 27 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 242f557f..be6feb7c 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
8use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 9use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
10use Symfony\Component\Routing\Annotation\Route; 10use Symfony\Component\Routing\Annotation\Route;
11use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
11use Wallabag\CoreBundle\Entity\Config; 12use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\CoreBundle\Entity\TaggingRule; 13use Wallabag\CoreBundle\Entity\TaggingRule;
13use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 14use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
@@ -330,6 +331,27 @@ class ConfigController extends Controller
330 } 331 }
331 332
332 /** 333 /**
334 * Change the locale for the current user.
335 *
336 * @param Request $request
337 * @param string $language
338 *
339 * @Route("/locale/{language}", name="changeLocale")
340 *
341 * @return \Symfony\Component\HttpFoundation\RedirectResponse
342 */
343 public function setLocaleAction(Request $request, $language = null)
344 {
345 $errors = $this->get('validator')->validate($language, (new LocaleConstraint()));
346
347 if (0 === \count($errors)) {
348 $request->getSession()->set('_locale', $language);
349 }
350
351 return $this->redirect($request->headers->get('referer', $this->generateUrl('homepage')));
352 }
353
354 /**
333 * Remove all tags for given tags and a given user and cleanup orphan tags. 355 * Remove all tags for given tags and a given user and cleanup orphan tags.
334 * 356 *
335 * @param array $tags 357 * @param array $tags
diff --git a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
index 367cdfb0..dc1db5c7 100644
--- a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
+++ b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php
@@ -6,8 +6,10 @@ use Symfony\Component\HttpFoundation\Session\Session;
6use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 6use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
7 7
8/** 8/**
9 * Stores the locale of the user in the session after the 9 * Stores the locale of the user in the session after the login.
10 * login. This can be used by the LocaleListener afterwards. 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.
11 * 13 *
12 * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html 14 * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html
13 */ 15 */
@@ -30,7 +32,7 @@ class UserLocaleListener
30 { 32 {
31 $user = $event->getAuthenticationToken()->getUser(); 33 $user = $event->getAuthenticationToken()->getUser();
32 34
33 if (null !== $user->getConfig()->getLanguage()) { 35 if (null !== $user->getConfig()->getLanguage() && null === $this->session->get('_locale')) {
34 $this->session->set('_locale', $user->getConfig()->getLanguage()); 36 $this->session->set('_locale', $user->getConfig()->getLanguage());
35 } 37 }
36 } 38 }