vendor/kunstmaan/form-bundle/EventListener/ConfigureActionsMenuListener.php line 39

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\FormBundle\EventListener;
  3. use Doctrine\ORM\EntityManager;
  4. use Kunstmaan\FormBundle\Entity\AbstractFormPage;
  5. use Kunstmaan\NodeBundle\Event\ConfigureActionMenuEvent;
  6. use Symfony\Component\Routing\Router;
  7. use Symfony\Component\Routing\RouterInterface;
  8. /**
  9.  * An event listener to add a formsubmissions link to the submenu of nodes.
  10.  */
  11. class ConfigureActionsMenuListener
  12. {
  13.     /**
  14.      * @var EntityManager
  15.      */
  16.     private $em;
  17.     /**
  18.      * @var Router
  19.      */
  20.     private $router;
  21.     /**
  22.      * @param EntityManager   $em     The entity manager
  23.      * @param RouterInterface $router The router
  24.      */
  25.     public function __construct(EntityManager $emRouterInterface $router)
  26.     {
  27.         $this->router $router;
  28.         $this->em $em;
  29.     }
  30.     /**
  31.      * Configure the form submissions link on top of the form in the sub action menu
  32.      */
  33.     public function onSubActionMenuConfigure(ConfigureActionMenuEvent $event)
  34.     {
  35.         $menu $event->getMenu();
  36.         $activeNodeVersion $event->getActiveNodeVersion();
  37.         if (!is_null($activeNodeVersion)) {
  38.             $page $activeNodeVersion->getRef($this->em);
  39.             if ($page instanceof AbstractFormPage) {
  40.                 $activeNodeTranslation $activeNodeVersion->getNodeTranslation();
  41.                 $menu->addChild('subaction.formsubmissions', ['uri' => $this->router->generate('KunstmaanFormBundle_formsubmissions_list', ['nodeTranslationId' => $activeNodeTranslation->getId()])]);
  42.             }
  43.         }
  44.     }
  45. }