|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Menu\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use Knp\Menu\FactoryInterface; |
|
6
|
|
|
use Knp\Menu\ItemInterface; |
|
7
|
|
|
use Knp\Menu\Provider\MenuProviderInterface; |
|
8
|
|
|
use LAG\AdminBundle\Factory\ConfigurationFactory; |
|
9
|
|
|
use LAG\AdminBundle\Routing\Resolver\RoutingResolverInterface; |
|
10
|
|
|
|
|
11
|
|
|
class MenuProvider implements MenuProviderInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var FactoryInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
private $factory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var ConfigurationFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
private $configurationFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var RoutingResolverInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $resolver; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private $menuConfigurations; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct( |
|
34
|
|
|
array $menuConfigurations, |
|
35
|
|
|
FactoryInterface $factory, |
|
36
|
|
|
ConfigurationFactory $configurationFactory, |
|
37
|
|
|
RoutingResolverInterface $resolver |
|
38
|
|
|
) { |
|
39
|
|
|
$this->factory = $factory; |
|
40
|
|
|
$this->configurationFactory = $configurationFactory; |
|
41
|
|
|
$this->resolver = $resolver; |
|
42
|
|
|
$this->menuConfigurations = $menuConfigurations; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function get(string $name, array $options = []): ItemInterface |
|
46
|
|
|
{ |
|
47
|
|
|
$menuConfiguration = $this->configurationFactory->createMenuConfiguration($name, []); |
|
48
|
|
|
$menuConfiguration = $menuConfiguration->all(); |
|
49
|
|
|
|
|
50
|
|
|
$menu = $this->factory->createItem('root', [ |
|
51
|
|
|
'attributes' => $menuConfiguration['attributes'], |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
|
|
foreach ($menuConfiguration['children'] as $itemConfiguration) { |
|
55
|
|
|
$menu->addChild($itemConfiguration['text'], [ |
|
56
|
|
|
'attributes' => $itemConfiguration['attributes'], |
|
57
|
|
|
'linkAttributes' => $itemConfiguration['linkAttributes'], |
|
58
|
|
|
'route' => $this->resolver->resolveOptions($itemConfiguration), |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $menu; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function has(string $name, array $options = []): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return key_exists($name, $this->menuConfigurations); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|