Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

NodeBundle/EventListener/NodeTabListener.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\NodeBundle\EventListener;
4
5
use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget;
6
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
7
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
8
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
9
use Kunstmaan\NodeBundle\Entity\PageTabInterface;
10
use Kunstmaan\NodeBundle\Event\AdaptFormEvent;
11
12
class NodeTabListener
13
{
14 1 View Code Duplication
    public function addTabs(TabPane $tabPane, PageTabInterface $page)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16 1
        foreach ($page->getTabs() as $pageTab) {
17 1
            $formWidget = new FormWidget();
18 1
            $formWidget->addType($pageTab->getInternalName(), $pageTab->getFormTypeClass(), $page);
19 1
            $tabPane->addTab(new Tab($pageTab->getTabTitle(), $formWidget), $pageTab->getPosition());
20
        }
21 1
    }
22
23 1
    public function adaptForm(AdaptFormEvent $event)
24
    {
25 1
        $page = $event->getPage();
26 1
        $tabPane = $event->getTabPane();
27
28 1
        if ($page instanceof HasNodeInterface === false) {
29
            return;
30
        }
31
32 1
        if ($page->isStructureNode() === true) {
33
            return;
34
        }
35
36
        /** @var PageTabInterface $page */
37 1
        if ($page instanceof PageTabInterface === false) {
38
            return;
39
        }
40
41 1
        $this->addTabs($tabPane, $page);
42 1
    }
43
}
44