1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Load AdminBundle configuration into the container. |
13
|
|
|
*/ |
14
|
|
|
class LAGAdminExtension extends Extension implements PrependExtensionInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Load the configuration into the container. |
18
|
|
|
*/ |
19
|
6 |
|
public function load(array $configs, ContainerBuilder $builder) |
20
|
|
|
{ |
21
|
6 |
|
$configuration = new Configuration(); |
22
|
6 |
|
$config = $this->processConfiguration($configuration, $configs); |
23
|
|
|
|
24
|
6 |
|
$loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config')); |
25
|
6 |
|
$loader->load('services.yaml'); |
26
|
|
|
|
27
|
6 |
|
if ('dev' === $builder->getParameter('kernel.environment')) { |
28
|
|
|
$loader->load('services_dev.yaml'); |
29
|
|
|
} |
30
|
6 |
|
$adminsConfig = []; |
31
|
6 |
|
$enableExtraConfig = true; |
32
|
|
|
|
33
|
6 |
|
if (!key_exists('application', $config)) { |
34
|
4 |
|
$config['application'] = [ |
35
|
|
|
'enable_menus' => true, |
36
|
|
|
'resources_path' => null, |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
6 |
|
if (key_exists('enable_extra_configuration', $config['application'])) { |
41
|
2 |
|
$enableExtraConfig = $config['application']['enable_extra_configuration']; |
42
|
|
|
} |
43
|
6 |
|
$applicationConfig = $config['application']; |
44
|
|
|
|
45
|
6 |
|
if (key_exists('admins', $config)) { |
46
|
6 |
|
$adminsConfig = $config['admins']; |
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
if (!key_exists('menus', $config)) { |
50
|
|
|
$config['menus'] = []; |
51
|
|
|
} |
52
|
6 |
|
$builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig); |
53
|
6 |
|
$builder->setParameter('lag.admin.application_configuration', $applicationConfig); |
54
|
6 |
|
$builder->setParameter('lag.admins', $adminsConfig); |
55
|
6 |
|
$builder->setParameter('lag.menus', $config['menus']); |
56
|
6 |
|
$builder->setParameter('lag.enable_menus', $config['application']['enable_menus']); |
57
|
6 |
|
$builder->setParameter('lag.admin.resources_path', $config['application']['resources_path']); |
58
|
6 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
2 |
|
public function getAlias() |
64
|
|
|
{ |
65
|
2 |
|
return 'lag_admin'; |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
public function prepend(ContainerBuilder $container) |
69
|
|
|
{ |
70
|
2 |
|
$container->prependExtensionConfig('knp_menu', [ |
71
|
1 |
|
'twig' => [ |
72
|
1 |
|
'template' => '@LAGAdmin/Menu/menu-base.html.twig', |
73
|
|
|
], |
74
|
|
|
]); |
75
|
2 |
|
} |
76
|
|
|
} |
77
|
|
|
|