]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ConfigController.php
Redirect to the current view instead of homepage
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
index a89bb7805b6bc98c9129620eaaa8ff4016c65efb..be6feb7cdd21b441229e72a26813f85e37b69c53 100644 (file)
@@ -2,12 +2,13 @@
 
 namespace Wallabag\CoreBundle\Controller;
 
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\Routing\Annotation\Route;
+use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
 use Wallabag\CoreBundle\Entity\Config;
 use Wallabag\CoreBundle\Entity\TaggingRule;
 use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
@@ -329,6 +330,27 @@ class ConfigController extends Controller
         return $this->redirect($request->headers->get('referer'));
     }
 
+    /**
+     * Change the locale for the current user.
+     *
+     * @param Request $request
+     * @param string  $language
+     *
+     * @Route("/locale/{language}", name="changeLocale")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function setLocaleAction(Request $request, $language = null)
+    {
+        $errors = $this->get('validator')->validate($language, (new LocaleConstraint()));
+
+        if (0 === \count($errors)) {
+            $request->getSession()->set('_locale', $language);
+        }
+
+        return $this->redirect($request->headers->get('referer', $this->generateUrl('homepage')));
+    }
+
     /**
      * Remove all tags for given tags and a given user and cleanup orphan tags.
      *
@@ -348,7 +370,7 @@ class ConfigController extends Controller
         $em = $this->getDoctrine()->getManager();
 
         foreach ($tags as $tag) {
-            if (0 === count($tag->getEntries())) {
+            if (0 === \count($tag->getEntries())) {
                 $em->remove($tag);
             }
         }