forked from avanzu/AdminThemeBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuBuilder.php
68 lines (59 loc) · 1.7 KB
/
MenuBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* MenuBuilder.php
* symfony3
* Date: 12.06.16
*/
namespace Avanzu\AdminThemeBundle\Menu;
use Avanzu\AdminThemeBundle\Event\KnpMenuEvent;
use Avanzu\AdminThemeBundle\Event\ThemeEvents;
use Avanzu\AdminThemeBundle\Routing\RouteAliasCollection;
use Knp\Menu\FactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class MenuBuilder
{
/**
* @var FactoryInterface
*/
private $factory;
/**
* @var RouteAliasCollection
*/
private $aliasCollection;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* DemoMenuBuilder constructor.
*
* @param FactoryInterface $factory
* @param RouteAliasCollection $aliasCollection
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
FactoryInterface $factory,
RouteAliasCollection $aliasCollection,
EventDispatcherInterface $eventDispatcher
) {
$this->factory = $factory;
$this->aliasCollection = $aliasCollection;
$this->eventDispatcher = $eventDispatcher;
}
public function createMainMenu(array $options)
{
$menu = $this->factory->createItem('root', [
'childrenAttributes' => ['class' => 'sidebar-menu'],
]);
$childOptions = [
'attributes' => ['class' => 'treeview'],
'childrenAttributes' => ['class' => 'treeview-menu'],
'labelAttributes' => [],
];
$this->eventDispatcher->dispatch(
ThemeEvents::THEME_SIDEBAR_SETUP_KNP_MENU,
new KnpMenuEvent($menu, $this->factory, $options, $childOptions)
);
return $menu;
}
}