1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Event\Listener\Menu; |
4
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Admin\Resource\Registry\ResourceRegistryInterface; |
6
|
|
|
use LAG\AdminBundle\Event\Events\Configuration\MenuConfigurationEvent; |
7
|
|
|
|
8
|
|
|
class LeftMenuConfigurationListener |
9
|
|
|
{ |
10
|
|
|
private ResourceRegistryInterface $registry; |
11
|
|
|
|
12
|
|
|
public function __construct(ResourceRegistryInterface $registry) |
13
|
|
|
{ |
14
|
|
|
$this->registry = $registry; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function __invoke(MenuConfigurationEvent $event): void |
18
|
|
|
{ |
19
|
|
|
$menuConfiguration = $event->getMenuConfiguration(); |
20
|
|
|
$menuConfiguration['attributes']['id'] = 'accordionSidebar'; |
21
|
|
|
$menuConfiguration['attributes']['class'] = 'navbar-nav bg-gradient-primary sidebar sidebar-dark accordion'; |
22
|
|
|
$menuConfiguration['extras']['brand'] = true; |
23
|
|
|
$menuConfiguration['extras']['homepage'] = true; |
24
|
|
|
|
25
|
|
|
if (isset($menuConfiguration['children']) && \is_array($menuConfiguration['children'])) { |
26
|
|
|
foreach ($menuConfiguration['children'] as $index => $item) { |
27
|
|
|
if (empty($item['attributes']['class'])) { |
28
|
|
|
$item['attributes']['class'] = 'nav-item'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if (empty($item['linkAttributes']['class'])) { |
32
|
|
|
$item['linkAttributes']['class'] = 'nav-link'; |
33
|
|
|
} |
34
|
|
|
$menuConfiguration['children'][$index] = $item; |
35
|
|
|
} |
36
|
|
|
} else { |
37
|
|
|
$menuConfiguration['children'] = []; |
38
|
|
|
|
39
|
|
|
// The default main menu is composed by links to the list action of each admin resource |
40
|
|
|
foreach ($this->registry->all() as $resourceName => $resource) { |
41
|
|
|
if (empty($resource->getConfiguration()['actions']) || !\array_key_exists('list', $resource->getConfiguration()['actions'])) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
$menuConfiguration['children'][$resourceName] = [ |
45
|
|
|
'admin' => $resourceName, |
46
|
|
|
'action' => 'list', |
47
|
|
|
'attributes' => [ |
48
|
|
|
'class' => 'nav-item', |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
$event->setMenuConfiguration($menuConfiguration); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|