Skip to content

Commit

Permalink
bug #35306 [FrameworkBundle] Make sure one can use fragments.hinclude…
Browse files Browse the repository at this point in the history
…_default_template (Nyholm)

This PR was squashed before being merged into the 4.4 branch (closes #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
  • Loading branch information
fabpot committed Jan 12, 2020
2 parents 7e1a7b7 + 25fd665 commit 8e0f0cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', [
'fragments' => [
'enabled' => true,
'hinclude_default_template' => 'global_hinclude_template',
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:fragments enabled="true" hinclude-default-template="global_hinclude_template"/>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
fragments:
enabled: true
hinclude_default_template: global_hinclude_template
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public function testAmbiguousWhenBothTemplatingAndFragments()
$this->createContainerFromFile('template_and_fragments');
}

public function testFragmentsAndHinclude()
{
$container = $this->createContainerFromFile('fragments_and_hinclude');
$this->assertTrue($container->hasParameter('fragment.renderer.hinclude.global_template'));
$this->assertEquals('global_hinclude_template', $container->getParameter('fragment.renderer.hinclude.global_template'));
}

public function testSsi()
{
$container = $this->createContainerFromFile('full');
Expand Down

0 comments on commit 8e0f0cc

Please sign in to comment.