VendorFormMenuBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Menu;
6
7
use Knp\Menu\FactoryInterface;
8
use Knp\Menu\ItemInterface;
9
use Odiseo\SyliusVendorPlugin\Entity\VendorInterface;
10
use Odiseo\SyliusVendorPlugin\Event\VendorFormMenuBuilderEvent;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
13
final class VendorFormMenuBuilder
14
{
15
    /** @var FactoryInterface */
16
    private $factory;
17
18
    /** @var EventDispatcherInterface */
19
    private $eventDispatcher;
20
21
    public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher)
22
    {
23
        $this->factory = $factory;
24
        $this->eventDispatcher = $eventDispatcher;
25
    }
26
27
    public function createMenu(array $options = []): ItemInterface
28
    {
29
        $menu = $this->factory->createItem('root');
30
31
        if (!array_key_exists('vendor', $options) || !$options['vendor'] instanceof VendorInterface) {
32
            return $menu;
33
        }
34
35
        $menu
36
            ->addChild('details')
37
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_details.html.twig')
38
            ->setLabel('sylius.ui.details')
39
            ->setCurrent(true)
40
        ;
41
42
        $menu
43
            ->addChild('profile')
44
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_profile.html.twig')
45
            ->setLabel('odiseo_sylius_vendor_plugin.ui.profile')
46
        ;
47
48
        $menu
49
            ->addChild('media')
50
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_media.html.twig')
51
            ->setLabel('sylius.ui.media')
52
        ;
53
54
        $this->eventDispatcher->dispatch(
55
            new VendorFormMenuBuilderEvent($this->factory, $menu, $options['vendor'])
56
        );
57
58
        return $menu;
59
    }
60
}
61