Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix regression in PageBundle and allows base template to be changed

  • Loading branch information...
commit 0c7a0aef0729f92ddfdc55265ddb1ed16b03a055 1 parent 1f86cc6
@rande rande authored
View
32 DependencyInjection/Compiler/GlobalVariablesCompilerPass.php
@@ -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')));
+ }
+}
View
7 DependencyInjection/Configuration.php
@@ -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')
View
12 DependencyInjection/SonataBlockExtension.php
@@ -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']);
}
/**
View
5 Resources/config/core.xml
@@ -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>
View
2  Resources/doc/reference/your_first_block.rst
@@ -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>
View
3  Resources/views/Block/block_core_action.html.twig
@@ -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 %}
View
2  Resources/views/Block/block_core_rss.html.twig
@@ -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>
View
2  Resources/views/Block/block_core_text.html.twig
@@ -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
2  SonataBlockBundle.php
@@ -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
45 Twig/GlobalVariables.php
@@ -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;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.