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
|
|
|
|