Skip to content

Commit 8e0f0cc

Browse files
committed
bug symfony#35306 [FrameworkBundle] Make sure one can use fragments.hinclude_default_template (Nyholm)
This PR was squashed before being merged into the 4.4 branch (closes symfony#35306). Discussion ---------- [FrameworkBundle] Make sure one can use fragments.hinclude_default_template | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Using `framework.fragments.hinclude_default_template` is not possible in 4.4. You will always get an exception saying: > You cannot set both "templating.hinclude_default_template" and "fragments.hinclude_default_template", please only use "fragments.hinclude_default_template". That is because in [fragment_renderer.xml](https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml#L8) we define the parameter `fragment.renderer.hinclude.global_template` to be an empty string, then in FrameworkExtension we are checking if it is null. This PR do a `!empty` check instead. I also added a test to show the bug. Commits ------- 25fd665 [FrameworkBundle] Make sure one can use fragments.hinclude_default_template
2 parents 7e1a7b7 + 25fd665 commit 8e0f0cc

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
523523

524524
return;
525525
}
526-
if ($container->hasParameter('fragment.renderer.hinclude.global_template') && null !== $container->getParameter('fragment.renderer.hinclude.global_template') && null !== $config['hinclude_default_template']) {
526+
if ($container->hasParameter('fragment.renderer.hinclude.global_template') && '' !== $container->getParameter('fragment.renderer.hinclude.global_template') && null !== $config['hinclude_default_template']) {
527527
throw new \LogicException('You cannot set both "templating.hinclude_default_template" and "fragments.hinclude_default_template", please only use "fragments.hinclude_default_template".');
528528
}
529529

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'fragments' => [
5+
'enabled' => true,
6+
'hinclude_default_template' => 'global_hinclude_template',
7+
],
8+
]);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:fragments enabled="true" hinclude-default-template="global_hinclude_template"/>
10+
</framework:config>
11+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
fragments:
3+
enabled: true
4+
hinclude_default_template: global_hinclude_template

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ public function testAmbiguousWhenBothTemplatingAndFragments()
170170
$this->createContainerFromFile('template_and_fragments');
171171
}
172172

173+
public function testFragmentsAndHinclude()
174+
{
175+
$container = $this->createContainerFromFile('fragments_and_hinclude');
176+
$this->assertTrue($container->hasParameter('fragment.renderer.hinclude.global_template'));
177+
$this->assertEquals('global_hinclude_template', $container->getParameter('fragment.renderer.hinclude.global_template'));
178+
}
179+
173180
public function testSsi()
174181
{
175182
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)