|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\Bridge\KnpMenu\Builder; |
|
6
|
|
|
|
|
7
|
|
|
use Knp\Menu\FactoryInterface; |
|
8
|
|
|
use Knp\Menu\ItemInterface; |
|
9
|
|
|
use LAG\AdminBundle\Event\Events\MenuCreatedEvent; |
|
10
|
|
|
use LAG\AdminBundle\Event\Events\MenuCreateEvent; |
|
11
|
|
|
use LAG\AdminBundle\Event\MenuEvents; |
|
12
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
|
13
|
|
|
|
|
14
|
|
|
class UserMenuBuilder |
|
15
|
|
|
{ |
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private FactoryInterface $factory, |
|
18
|
|
|
private EventDispatcherInterface $eventDispatcher, |
|
19
|
|
|
) { |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function createMenu(array $options = []): ItemInterface |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$menu = $this->factory->createItem('root'); |
|
25
|
|
|
$this->eventDispatcher->dispatch($event = new MenuCreateEvent($menu), MenuEvents::MENU_CREATE); |
|
26
|
|
|
$this->eventDispatcher->dispatch($event = new MenuCreateEvent($event->getMenu()), sprintf( |
|
27
|
|
|
MenuEvents::NAMED_EVENT_PATTERN, |
|
28
|
|
|
'user', |
|
29
|
|
|
)); |
|
30
|
|
|
$menu = $event->getMenu(); |
|
31
|
|
|
$menu->addChild('lag_admin.security.logout', [ |
|
32
|
|
|
'route' => 'lag_admin.logout', |
|
33
|
|
|
'extras' => ['icon' => 'sign-out-alt'], |
|
34
|
|
|
]); |
|
35
|
|
|
$this->eventDispatcher->dispatch(new MenuCreatedEvent($menu), MenuEvents::MENU_CREATED); |
|
36
|
|
|
$this->eventDispatcher->dispatch(new MenuCreatedEvent($menu), sprintf( |
|
37
|
|
|
MenuEvents::NAMED_EVENT_PATTERN, |
|
38
|
|
|
'user', |
|
39
|
|
|
)); |
|
40
|
|
|
|
|
41
|
|
|
return $menu; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.