Permalink
Browse files

Fix regression in PageBundle and allows base template to be changed

  • Loading branch information...
1 parent 1f86cc6 commit 0c7a0aef0729f92ddfdc55265ddb1ed16b03a055 @rande rande committed Nov 9, 2012
@@ -0,0 +1,32 @@
+<?php
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\BlockBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
+
+/**
+ * GlobalVariablesCompilerPass
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+class GlobalVariablesCompilerPass implements CompilerPassInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ function process(ContainerBuilder $container)
+ {
+ $container->getDefinition('twig')
+ ->addMethodCall('addGlobal', array('sonata_block', new Reference('sonata.block.twig.global')));
+ }
+}
@@ -34,6 +34,13 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()
+ ->arrayNode('templates')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('block_base')->defaultValue(null)->end()
+ ->end()
+ ->end()
+
->arrayNode('blocks')
->useAttributeAsKey('id')
->prototype('array')
@@ -47,6 +47,18 @@ public function load(array $configs, ContainerBuilder $container)
$this->configureLoaderChain($container, $config);
$this->configureCache($container, $config);
$this->configureForm($container, $config);
+
+ $bundles = $container->getParameter('kernel.bundles');
+ if ($config['templates']['block_base'] === null) {
+ if (isset($bundles['SonataPageBundle'])) {
+ $config['templates']['block_base'] = 'SonataPageBundle:Block:block_base.html.twig';
+ } else {
+ $config['templates']['block_base'] = 'SonataBlockBundle:Block:block_base.html.twig';
+ }
+ }
+
+ $container->getDefinition('sonata.block.twig.global')
+ ->replaceArgument(1, $config['templates']);
}
/**
@@ -36,5 +36,10 @@
<argument />
</service>
+
+ <service id="sonata.block.twig.global" class="Sonata\BlockBundle\Twig\GlobalVariables" >
+ <argument type="service" id="service_container" />
+ <argument />
+ </service>
</services>
</container>
@@ -140,7 +140,7 @@ defined, a error message is displayed.
.. code-block:: jinja
- {% extends 'SonataBlockBundle:Block:block_base.html.twig' %}
+ {% extends sonata_block.templates.block_base %}
{% block block %}
<h3>{{ settings.title }}</h3>
@@ -9,7 +9,8 @@ file that was distributed with this source code.
#}
-{% extends 'SonataBlockBundle:Block:block_base.html.twig' %}
+{% extends sonata_block.templates.block_base %}
+
{% block block %}
{{ content|raw }}
{% endblock %}
@@ -8,7 +8,7 @@ For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
-{% extends 'SonataBlockBundle:Block:block_base.html.twig' %}
+{% extends sonata_block.templates.block_base %}
{% block block %}
<h3 class="sonata-feed-title">{{ settings.title }}</h3>
@@ -9,7 +9,7 @@ file that was distributed with this source code.
#}
-{% extends 'SonataBlockBundle:Block:block_base.html.twig' %}
+{% extends sonata_block.templates.block_base %}
{% block block %}
{{ settings.content|raw }}
View
@@ -13,11 +13,13 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Sonata\BlockBundle\DependencyInjection\Compiler\TweakCompilerPass;
+use Sonata\BlockBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
class SonataBlockBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new TweakCompilerPass());
+ $container->addCompilerPass(new GlobalVariablesCompilerPass());
}
}
View
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\BlockBundle\Twig;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * GlobalVariables
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+class GlobalVariables
+{
+ protected $container;
+
+ protected $templates;
+
+ /**
+ *
+ * @param ContainerInterface $container
+ * @param array $templates
+ */
+ public function __construct(ContainerInterface $container, array $templates)
+ {
+ $this->container = $container;
+ $this->templates = $templates;
+ }
+
+ /**
+ * @return array
+ */
+ public function getTemplates()
+ {
+ return $this->templates;
+ }
+}

0 comments on commit 0c7a0ae

Please sign in to comment.