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\FactoryInterface; |
15
|
|
|
use Knp\Menu\ItemInterface; |
16
|
|
|
use Sylius\Bundle\AdminBundle\Event\ProductVariantMenuBuilderEvent; |
17
|
|
|
use Sylius\Component\Product\Model\ProductVariantInterface; |
18
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Jan Góralski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class ProductVariantFormMenuBuilder |
24
|
|
|
{ |
25
|
|
|
const EVENT_NAME = 'sylius.menu.admin.product_variant.form'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var FactoryInterface |
29
|
|
|
*/ |
30
|
|
|
private $factory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EventDispatcherInterface |
34
|
|
|
*/ |
35
|
|
|
private $eventDispatcher; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param FactoryInterface $factory |
39
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
40
|
|
|
*/ |
41
|
|
|
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher) |
42
|
|
|
{ |
43
|
|
|
$this->factory = $factory; |
44
|
|
|
$this->eventDispatcher = $eventDispatcher; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $options |
49
|
|
|
* |
50
|
|
|
* @return ItemInterface |
51
|
|
|
*/ |
52
|
|
|
public function createMenu(array $options = []) |
53
|
|
|
{ |
54
|
|
|
$menu = $this->factory->createItem('root'); |
55
|
|
|
|
56
|
|
|
if (!array_key_exists('product_variant', $options) || !$options['product_variant'] instanceof ProductVariantInterface) { |
57
|
|
|
return $menu; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$menu |
61
|
|
|
->addChild('details') |
62
|
|
|
->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_details.html.twig') |
63
|
|
|
->setLabel('sylius.ui.details') |
64
|
|
|
->setCurrent(true) |
65
|
|
|
; |
66
|
|
|
|
67
|
|
|
$menu |
68
|
|
|
->addChild('taxes') |
69
|
|
|
->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_taxes.html.twig') |
70
|
|
|
->setLabel('sylius.ui.taxes') |
71
|
|
|
; |
72
|
|
|
|
73
|
|
|
$this->eventDispatcher->dispatch( |
74
|
|
|
self::EVENT_NAME, |
75
|
|
|
new ProductVariantMenuBuilderEvent($this->factory, $menu, $options['product_variant']) |
|
|
|
|
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return $menu; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.