forked from kevinpapst/AdminLTEBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminLTEExtension.php
106 lines (87 loc) · 3.45 KB
/
AdminLTEExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
* This file is part of the AdminLTE bundle.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace KevinPapst\AdminLTEBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* Loads AdminLTEBundle configuration
*
* @see http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class AdminLTEExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$options = $this->getContextOptions($config);
if (!empty($config)) {
$container->setParameter('admin_lte_theme.options', $options);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
if ($options['knp_menu']['enable'] === true) {
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/container'));
$loader->load('knp-menu.yml');
}
}
/**
* Merge available configuration options, so they are all available for the ContextHelper.
*
* @param array $config
* @return array
*/
protected function getContextOptions(array $config = [])
{
$sidebar = [];
if (isset($config['control_sidebar']) && !empty($config['control_sidebar'])) {
$sidebar = $config['control_sidebar'];
}
$contextOptions = (array) ($config['options'] ?? []);
$contextOptions['control_sidebar'] = $sidebar;
$contextOptions['knp_menu'] = (array) $config['knp_menu'];
$contextOptions = array_merge($contextOptions, $config['theme']);
return $contextOptions;
}
/**
* @see https://symfony.com/doc/current/bundles/prepend_extension.html
*
* @param ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
$configuration = new Configuration();
$configs = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration($configuration, $configs);
$options = (array) ($config['options'] ?? []);
$routes = (array) ($config['routes'] ?? []);
$container->setParameter('admin_lte_theme.options', $options);
$container->setParameter('admin_lte_theme.routes', $routes);
if (!array_key_exists('form_theme', $options) || null === ($theme = $options['form_theme'])) {
return;
}
$themes = [
'default' => '@AdminLTE/layout/form-theme.html.twig',
'horizontal' => '@AdminLTE/layout/form-theme-horizontal.html.twig',
];
if (!array_key_exists($theme, $themes)) {
return;
}
$bundles = $container->getParameter('kernel.bundles');
// register the form theme
if (isset($bundles['TwigBundle'])) {
$container->prependExtensionConfig('twig', ['form_theme' => [$themes[$theme]]]);
}
}
}