From 80dee1e7e7a29b6fa2eca3393ffa40c9e5beb4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 22 Sep 2014 23:27:04 +0200 Subject: [PATCH] automatic configuration for the bundle --- DependencyInjection/CLChillMainExtension.php | 41 ++++++++++++-------- DependencyInjection/Configuration.php | 10 +++-- Resources/views/layout.html.twig | 8 ++-- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/DependencyInjection/CLChillMainExtension.php b/DependencyInjection/CLChillMainExtension.php index 04c3f5994..3cf9f4be0 100644 --- a/DependencyInjection/CLChillMainExtension.php +++ b/DependencyInjection/CLChillMainExtension.php @@ -22,30 +22,39 @@ class CLChillMainExtension extends Extension implements PrependExtensionInterfac { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); + + $container->setParameter('cl_chill_main.installation_name', + $config['installation_name']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); } - public function prepend(ContainerBuilder $container) { + public function prepend(ContainerBuilder $container) + { $bundles = $container->getParameter('kernel.bundles'); - - //Configure FOSUSerBundle - if (!isset($bundles['FOSUserBundle'])) { - throw new MissingBundleException('FOSUserBundle'); + //add CLChillMain to assetic-enabled bundles + if (!isset($bundles['AsseticBundle'])) { + throw new MissingBundleException('AsseticBundle'); } + + $asseticConfig = $container->getExtensionConfig('assetic'); + $asseticConfig['bundles'][] = 'CLChillMainBundle'; + $container->prependExtensionConfig('assetic', + array('bundles' => array('CLChillMainBundle'))); + + //add installation_name to globals + $chillMainConfig = $container->getExtensionConfig($this->getAlias()); + $config = $this->processConfiguration(new Configuration(), $chillMainConfig); + $twigConfig = array( + 'globals' => array( + 'installation' => array( + 'name' => $config['installation_name'] + ) + ) + ); + $container->prependExtensionConfig('twig', $twigConfig); - $db_driver = array('db_driver' => 'orm'); - $container->prependExtensionConfig('fos_user', $db_driver); - - $user_class = array('user_class' => 'CL\Chill\MainBundle\Entity\Agent'); - $container->prependExtensionConfig('fos_user', $user_class); - - $registration_form = array('registration' => array( - 'form' => array('type' => 'chill_user_registration'))); - $container->prependExtensionConfig('fos_user', $registration_form); - - } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bff6c7c4f..400d3386d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,9 +20,13 @@ class Configuration implements ConfigurationInterface $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('cl_chill_main'); - // Here you should define the parameters that are allowed to - // configure your bundle. See the documentation linked above for - // more information on that topic. + $rootNode + ->children() + ->scalarNode('installation_name') + ->cannotBeEmpty() + ->defaultValue('Chill') + ->end() + ->end(); return $treeBuilder; } diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 6d1c5f6a0..685455242 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -54,11 +54,11 @@ @@ -82,7 +82,7 @@
  • -
    + @@ -93,7 +93,7 @@
  • - +