|
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\Resource\Registry\ResourceRegistryInterface; |
|
8
|
|
|
use LAG\AdminBundle\Factory\Configuration\AdminConfigurationFactoryInterface; |
|
9
|
|
|
use LAG\AdminBundle\Routing\Route\RouteNameGeneratorInterface; |
|
10
|
|
|
use LAG\AdminBundle\Translation\Helper\TranslationHelperInterface; |
|
11
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
|
12
|
|
|
use function Symfony\Component\String\u; |
|
13
|
|
|
|
|
14
|
|
|
class LeftMenuBuilder implements MenuBuilderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use MenuBuilderTrait; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
private FactoryInterface $factory, |
|
20
|
|
|
private ResourceRegistryInterface $resourceRegistry, |
|
21
|
|
|
private TranslationHelperInterface $translationHelper, |
|
22
|
|
|
private AdminConfigurationFactoryInterface $adminConfigurationFactory, |
|
23
|
|
|
private RouteNameGeneratorInterface $routeNameGenerator, |
|
24
|
|
|
private EventDispatcherInterface $eventDispatcher, |
|
25
|
|
|
) |
|
26
|
|
|
{ |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function createMenu(array $options = []): ItemInterface |
|
30
|
|
|
{ |
|
31
|
|
|
$menu = $this->factory->createItem('root'); |
|
32
|
|
|
|
|
33
|
|
|
foreach ($this->resourceRegistry->all() as $resource) { |
|
34
|
|
|
$configuration = $this |
|
35
|
|
|
->adminConfigurationFactory |
|
36
|
|
|
->create($resource->getName(), $resource->getConfiguration()) |
|
37
|
|
|
; |
|
38
|
|
|
|
|
39
|
|
|
if (!$configuration->hasAction('list')) { |
|
40
|
|
|
continue; |
|
41
|
|
|
} |
|
42
|
|
|
$translationKey = u($resource->getName())->snake()->toString(); |
|
43
|
|
|
$menu->addChild($this->translationHelper->getTranslationKey($translationKey), [ |
|
44
|
|
|
'route' => $this->routeNameGenerator->generateRouteName($resource->getName(), 'list'), |
|
45
|
|
|
]); |
|
46
|
|
|
} |
|
47
|
|
|
$this->dispatchMenuEvents('left', $menu); |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
return $menu; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|