|
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 SM\Factory\FactoryInterface as StateMachineFactoryInterface; |
|
17
|
|
|
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent; |
|
18
|
|
|
use Sylius\Component\Order\OrderTransitions; |
|
19
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class OrderShowMenuBuilder |
|
25
|
|
|
{ |
|
26
|
|
|
const EVENT_NAME = 'sylius.menu.admin.order.show'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var FactoryInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $factory; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var EventDispatcherInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $eventDispatcher; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var StateMachineFactoryInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $stateMachineFactory; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param FactoryInterface $factory |
|
45
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
|
46
|
|
|
* @param StateMachineFactoryInterface $stateMachineFactory, |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
FactoryInterface $factory, |
|
50
|
|
|
EventDispatcherInterface $eventDispatcher, |
|
51
|
|
|
StateMachineFactoryInterface $stateMachineFactory |
|
52
|
|
|
) { |
|
53
|
|
|
$this->factory = $factory; |
|
54
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
55
|
|
|
$this->stateMachineFactory = $stateMachineFactory; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param array $options |
|
60
|
|
|
* |
|
61
|
|
|
* @return ItemInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
public function createMenu(array $options) |
|
64
|
|
|
{ |
|
65
|
|
|
$menu = $this->factory->createItem('root'); |
|
66
|
|
|
|
|
67
|
|
|
if (!isset($options['order'])) { |
|
68
|
|
|
return $menu; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$order = $options['order']; |
|
72
|
|
|
|
|
73
|
|
|
$menu |
|
74
|
|
|
->addChild('order_history', [ |
|
75
|
|
|
'route' => 'sylius_admin_order_history', |
|
76
|
|
|
'routeParameters' => ['id' => $order->getId()] |
|
77
|
|
|
]) |
|
78
|
|
|
->setAttribute('type', 'link') |
|
79
|
|
|
->setLabel('sylius.ui.history') |
|
80
|
|
|
->setLabelAttribute('icon', 'history') |
|
81
|
|
|
; |
|
82
|
|
|
|
|
83
|
|
|
$stateMachine = $this->stateMachineFactory->get($order, OrderTransitions::GRAPH); |
|
84
|
|
|
if ($stateMachine->can(OrderTransitions::TRANSITION_CANCEL)) { |
|
85
|
|
|
$menu |
|
86
|
|
|
->addChild('cancel', [ |
|
87
|
|
|
'route' => 'sylius_admin_order_cancel', |
|
88
|
|
|
'routeParameters' => ['id' => $order->getId()] |
|
89
|
|
|
]) |
|
90
|
|
|
->setAttribute('type', 'transition') |
|
91
|
|
|
->setLabel('sylius.ui.cancel') |
|
92
|
|
|
->setLabelAttribute('icon', 'ban') |
|
93
|
|
|
->setLabelAttribute('color', 'yellow') |
|
94
|
|
|
; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->eventDispatcher->dispatch( |
|
98
|
|
|
self::EVENT_NAME, |
|
99
|
|
|
new OrderShowMenuBuilderEvent($this->factory, $menu, $order, $stateMachine) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
return $menu; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.