vendor/kevinpapst/adminlte-bundle/DependencyInjection/AdminLTEExtension.php line 74

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