|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Bridge\KnpMenu\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use Knp\Menu\FactoryInterface; |
|
6
|
|
|
use Knp\Menu\ItemInterface; |
|
7
|
|
|
use LAG\AdminBundle\Admin\Helper\AdminContextInterface; |
|
8
|
|
|
use LAG\AdminBundle\Routing\Route\RouteNameGeneratorInterface; |
|
9
|
|
|
use LAG\AdminBundle\Translation\Helper\TranslationHelperInterface; |
|
10
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
|
11
|
|
|
|
|
12
|
|
|
class TopMenuBuilder implements MenuBuilderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use MenuBuilderTrait; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private FactoryInterface $factory, |
|
18
|
|
|
private AdminContextInterface $adminContext, |
|
19
|
|
|
private RouteNameGeneratorInterface $routeNameGenerator, |
|
20
|
|
|
private TranslationHelperInterface $translationHelper, |
|
21
|
|
|
private EventDispatcherInterface $eventDispatcher, |
|
22
|
|
|
) |
|
23
|
|
|
{ |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function createMenu(array $options = []): ItemInterface |
|
27
|
|
|
{ |
|
28
|
|
|
$menu = $this->factory->createItem('root', $options); |
|
29
|
|
|
|
|
30
|
|
|
if (!$this->adminContext->hasAdmin()) { |
|
31
|
|
|
return $menu; |
|
32
|
|
|
} |
|
33
|
|
|
$admin = $this->adminContext->getAdmin(); |
|
34
|
|
|
$action = $admin->getAction()->getName(); |
|
35
|
|
|
|
|
36
|
|
|
if ($action === 'list') { |
|
37
|
|
|
if ($admin->getConfiguration()->hasAction('create')) { |
|
38
|
|
|
$menu->addChild($this->translationHelper->getTranslationKey('create', $admin->getName()), [ |
|
39
|
|
|
'route' => $this->routeNameGenerator->generateRouteName($admin->getName(), 'create'), |
|
40
|
|
|
'extras' => [ |
|
41
|
|
|
'icon' => 'plus' |
|
42
|
|
|
], |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
$this->dispatchMenuEvents('top', $menu); |
|
47
|
|
|
|
|
48
|
|
|
return $menu; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|