Completed
Push — master ( ea0a23...156714 )
by Joachim
12s queued 11s
created

BrandFormMenuBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createMenu() 0 27 3
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\Menu;
6
7
use Knp\Menu\FactoryInterface;
8
use Knp\Menu\ItemInterface;
9
use Loevgaard\SyliusBrandPlugin\Event\BrandMenuBuilderEvent;
10
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
13
final class BrandFormMenuBuilder
14
{
15
    public const EVENT_NAME = 'loevgaard_sylius_brand.menu.admin.brand.form';
16
17
    /** @var FactoryInterface */
18
    private $factory;
19
20
    /** @var EventDispatcherInterface */
21
    private $eventDispatcher;
22
23
    public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher)
24
    {
25
        $this->factory = $factory;
26
        $this->eventDispatcher = $eventDispatcher;
27
    }
28
29
    public function createMenu(array $options = []): ItemInterface
30
    {
31
        $menu = $this->factory->createItem('root');
32
33
        if (!array_key_exists('brand', $options) || !$options['brand'] instanceof BrandInterface) {
34
            return $menu;
35
        }
36
37
        $menu
38
            ->addChild('details')
39
            ->setAttribute('template', '@LoevgaardSyliusBrandPlugin/Admin/Brand/Tab/_details.html.twig')
40
            ->setLabel('sylius.ui.details')
41
            ->setCurrent(true)
42
        ;
43
44
        $menu
45
            ->addChild('media')
46
            ->setAttribute('template', '@LoevgaardSyliusBrandPlugin/Admin/Brand/Tab/_media.html.twig')
47
            ->setLabel('sylius.ui.media')
48
        ;
49
50
        $this->eventDispatcher->dispatch(
51
            self::EVENT_NAME,
52
            new BrandMenuBuilderEvent($this->factory, $menu, $options['brand'])
53
        );
54
55
        return $menu;
56
    }
57
}
58