Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

EventListener/ConfigureActionsMenuListener.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FormBundle\EventListener;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\FormBundle\Entity\AbstractFormPage;
7
use Kunstmaan\NodeBundle\Event\ConfigureActionMenuEvent;
8
use Symfony\Component\Routing\RouterInterface;
9
10
/**
11
 * An event listener to add a formsubmissions link to the submenu of nodes.
12
 */
13
class ConfigureActionsMenuListener
14
{
15
    /**
16
     * @var EntityManager
17
     */
18
    private $em;
19
20
    /**
21
     * @var Router
22
     */
23
    private $router;
24
25
    /**
26
     * @param EntityManager   $em     The entity manager
27
     * @param RouterInterface $router The router
28
     */
29
    public function __construct(EntityManager $em, RouterInterface $router)
30
    {
31
        $this->router = $router;
0 ignored issues
show
Documentation Bug introduced by
It seems like $router of type object<Symfony\Component\Routing\RouterInterface> is incompatible with the declared type object<Kunstmaan\FormBundle\EventListener\Router> of property $router.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        $this->em = $em;
33
    }
34
35
    /**
36
     * Configure the form submissions link on top of the form in the sub action menu
37
     *
38
     * @param ConfigureActionMenuEvent $event
39
     */
40
    public function onSubActionMenuConfigure(ConfigureActionMenuEvent $event)
41
    {
42
        $menu = $event->getMenu();
43
        $activeNodeVersion = $event->getActiveNodeVersion();
44
45
        if (!is_null($activeNodeVersion)) {
46
            $page = $activeNodeVersion->getRef($this->em);
47
            if ($page instanceof AbstractFormPage) {
48
                $activeNodeTranslation = $activeNodeVersion->getNodeTranslation();
49
                $menu->addChild('subaction.formsubmissions', array('uri' => $this->router->generate('KunstmaanFormBundle_formsubmissions_list', array('nodeTranslationId' => $activeNodeTranslation->getId()))));
50
            }
51
        }
52
    }
53
}
54