Completed
Push — master ( 12ace7...d998d0 )
by Kamil
35:58
created

MainMenuBuilder::addConfigurationMenu()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\AdminBundle\Menu;
13
14
use Knp\Menu\ItemInterface;
15
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
16
17
/**
18
 * @author Paweł Jędrzejewski <[email protected]>
19
 */
20
final class MainMenuBuilder extends AbstractAdminMenuBuilder
21
{
22
    const EVENT_NAME = 'sylius.menu.admin.main';
23
24
    /**
25
     * @return ItemInterface
26
     */
27
    public function createMenu()
28
    {
29
        $menu = $this->factory->createItem('root');
30
31
        $this->addConfigurationMenu($menu);
32
33
        $this->eventDispatcher->dispatch(self::EVENT_NAME, new MenuBuilderEvent($this->factory, $menu));
34
35
        return $menu;
36
    }
37
38
    /**
39
     * @param ItemInterface $menu
40
     */
41
    private function addConfigurationMenu(ItemInterface $menu)
42
    {
43
        $child = $menu
44
            ->addChild('configuration')
45
            ->setLabel('sylius.menu.admin.main.configuration.header')
46
        ;
47
48
        if (!$child->hasChildren()) {
49
            $menu->removeChild('configuration');
50
        }
51
    }
52
}
53