X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FConfigController.php;h=be6feb7cdd21b441229e72a26813f85e37b69c53;hb=9a57653aec85b0f5220436d5cb76545e66c24a11;hp=a89bb7805b6bc98c9129620eaaa8ff4016c65efb;hpb=3ef055ced3d6ea0d2f15ba660602545f477e9c3c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index a89bb780..be6feb7c 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -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); } }