Passed
Push — master ( b31e19...f7c593 )
by Odiseo
08:36
created

VendorFormMenuBuilder::createMenu()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 19
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 32
rs 9.6333
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\VendorMenuBuilderEvent;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
13
final class VendorFormMenuBuilder
14
{
15
    public const EVENT_NAME = 'odiseo_sylius_vendor_plugin.menu.admin.vendor.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('vendor', $options) || !$options['vendor'] instanceof VendorInterface) {
34
            return $menu;
35
        }
36
37
        $menu
38
            ->addChild('details')
39
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_details.html.twig')
40
            ->setLabel('sylius.ui.details')
41
            ->setCurrent(true)
42
        ;
43
44
        $menu
45
            ->addChild('profile')
46
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_profile.html.twig')
47
            ->setLabel('odiseo_sylius_vendor_plugin.ui.profile')
48
        ;
49
50
        $menu
51
            ->addChild('media')
52
            ->setAttribute('template', '@OdiseoSyliusVendorPlugin/Admin/Vendor/Tab/_media.html.twig')
53
            ->setLabel('sylius.ui.media')
54
        ;
55
56
        $this->eventDispatcher->dispatch(
57
            new VendorMenuBuilderEvent($this->factory, $menu, $options['vendor'])
58
        );
59
60
        return $menu;
61
    }
62
}
63