1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Veslo project <https://github.com/symfony-doge/veslo>. |
5
|
|
|
* |
6
|
|
|
* (C) 2019 Pavel Petrov <[email protected]>. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Veslo\AppBundle\Menu; |
17
|
|
|
|
18
|
|
|
use Knp\Menu\FactoryInterface; |
19
|
|
|
use Knp\Menu\ItemInterface; |
20
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
21
|
|
|
use Veslo\AppBundle\Event\Menu\ConfigureEvent; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Application menu builder |
25
|
|
|
*/ |
26
|
|
|
class Builder |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Factory to create items |
30
|
|
|
* |
31
|
|
|
* @var FactoryInterface |
32
|
|
|
*/ |
33
|
|
|
private $menuFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The central point of event listener system |
37
|
|
|
* |
38
|
|
|
* @var EventDispatcherInterface |
39
|
|
|
*/ |
40
|
|
|
private $eventDispatcher; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* MenuBuilder constructor. |
44
|
|
|
* |
45
|
|
|
* @param FactoryInterface $menuFactory Factory to create items |
46
|
|
|
* @param EventDispatcherInterface $eventDispatcher The central point of event listener system |
47
|
|
|
*/ |
48
|
|
|
public function __construct(FactoryInterface $menuFactory, EventDispatcherInterface $eventDispatcher) |
49
|
|
|
{ |
50
|
|
|
$this->menuFactory = $menuFactory; |
51
|
|
|
$this->eventDispatcher = $eventDispatcher; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns root item for application menu tree rendering |
56
|
|
|
* |
57
|
|
|
* @return ItemInterface |
58
|
|
|
*/ |
59
|
|
|
public function createMainMenu(): ItemInterface |
60
|
|
|
{ |
61
|
|
|
$root = $this->menuFactory->createItem('root'); |
62
|
|
|
|
63
|
|
|
$menuConfigureEvent = new ConfigureEvent($root); |
64
|
|
|
$this->eventDispatcher->dispatch(ConfigureEvent::NAME, $menuConfigureEvent); |
65
|
|
|
|
66
|
|
|
return $root; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|