diff --git a/EventListener/AdminLocaleListener.php b/EventListener/AdminLocaleListener.php index e511235d..5bf06624 100644 --- a/EventListener/AdminLocaleListener.php +++ b/EventListener/AdminLocaleListener.php @@ -3,6 +3,7 @@ namespace Kunstmaan\AdminBundle\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Translation\TranslatorInterface; @@ -29,24 +30,29 @@ class AdminLocaleListener implements EventSubscriberInterface private $defaultAdminlocale; /** - * @param SecurityContext $context + * @param SecurityContext $context * @param TranslatorInterface $translator - * @param string $defaultAdminLocale + * @param string $defaultAdminLocale */ public function __construct(SecurityContext $context, TranslatorInterface $translator, $defaultAdminLocale) { - $this->translator = $translator; - $this->context = $context; + $this->translator = $translator; + $this->context = $context; $this->defaultAdminlocale = $defaultAdminLocale; } /** - * onKernelView event + * onKernelRequest * * @param GetResponseEvent $event */ - public function onKernelView(GetResponseEvent $event) + public function onKernelRequest(GetResponseEvent $event) { + if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + // return immediately + return; + } + $url = $event->getRequest()->getRequestUri(); if ($this->context->getToken()) { diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 004e2fa5..25cfdd20 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -28,7 +28,7 @@ services: class: Kunstmaan\AdminBundle\EventListener\AdminLocaleListener arguments: ["@security.context", "@translator", "%kuma_admin.default_admin_locale%"] tags: - - { name: kernel.event_listener, event: 'kernel.view' } + - { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest' } kunstmaan_admin.menu.twig.extension: class: Kunstmaan\AdminBundle\Twig\MenuTwigExtension