diff --git a/src/Kunstmaan/NodeBundle/EventListener/SlugListener.php b/src/Kunstmaan/NodeBundle/EventListener/SlugListener.php index 4453b17194..5eabfdd7ec 100644 --- a/src/Kunstmaan/NodeBundle/EventListener/SlugListener.php +++ b/src/Kunstmaan/NodeBundle/EventListener/SlugListener.php @@ -3,6 +3,7 @@ namespace Kunstmaan\NodeBundle\EventListener; use Kunstmaan\NodeBundle\Controller\SlugActionInterface; +use Kunstmaan\NodeBundle\Entity\NodeTranslation; use Kunstmaan\NodeBundle\Event\Events; use Kunstmaan\NodeBundle\Event\SlugSecurityEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -10,14 +11,8 @@ use Doctrine\ORM\EntityManager; use Symfony\Component\HttpKernel\Controller\ControllerResolver; - -/** - * Class SlugListener - * @package Kunstmaan\NodeBundle\EventListener - */ class SlugListener { - /** * @var EntityManager */ @@ -28,7 +23,6 @@ class SlugListener */ protected $resolver; - /** * @var EventDispatcher */ @@ -53,23 +47,27 @@ public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); - //check if the event has anything to do with nodeTranslations, if not this method can be skipped + // Check if the event has anything to do with nodeTranslations, if not this method can be skipped if (!$request->attributes->has('_nodeTranslation')) { return; } $nodeTranslation = $request->attributes->get('_nodeTranslation'); + if (!($nodeTranslation instanceof NodeTranslation)) { + $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslation); + $request->attributes->set('_nodeTranslation', $nodeTranslation); + } $entity = $nodeTranslation->getRef($this->em); - //if the entity is an instance of the SlugControllerActionInterface, change the controller + // If the entity is an instance of the SlugControllerActionInterface, change the controller if ($entity instanceof SlugActionInterface) { $request->attributes->set('_entity', $entity); - //do security check by firing an event that gets handled by the SlugSecurityListener + // Do security check by firing an event that gets handled by the SlugSecurityListener $securityEvent = new SlugSecurityEvent(); $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent); - //set the right controller + // Set the right controller $request->attributes->set('_controller', $entity->getControllerAction()); $event->setController($this->resolver->getController($request)); }