8000 feature #30959 [FrameworkBundle] [TwigBundle] Move the hinclude key a… · symfony/symfony@35b1ded · GitHub
[go: up one dir, main page]

Skip to content

Commit 35b1ded

Browse files
committed
feature #30959 [FrameworkBundle] [TwigBundle] Move the hinclude key away from templating (Simperfit)
This PR was squashed before being merged into the 4.3-dev branch (closes #30959). Discussion ---------- [FrameworkBundle] [TwigBundle] Move the hinclude key away from templating | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #30874 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | to do when pr is validated. <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Maybe I shouldn't move directly the config key from templating to the other, but since the templating component has been deprecated we may change this directly without deprecating that key alone, WDYT ? Commits ------- 4f39339 [FrameworkBundle] [TwigBundle] Move the hinclude key away from templating
2 parents 9b9d416 + 4f39339 commit 35b1ded

File tree

8 files changed

+71
-1
lines changed

8 files changed

+71
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ private function addFragmentsSection(ArrayNodeDefinition $rootNode)
191191
->info('fragments configuration')
192192
->canBeEnabled()
193193
->children()
194+
->scalarNode('hinclude_default_template')->defaultNull()->end()
194195
->scalarNode('path')->defaultValue('/_fragment')->end()
195196
->end()
196197
->end()
@@ -610,7 +611,7 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
610611
->then(function () { return ['enabled' => false, 'engines' => false]; })
611612
->end()
612613
->children()
613-
->scalarNode('hinclude_default_template')->defaultNull()->end()
614+
->scalarNode('hinclude_default_template')->setDeprecated('Setting "templating.hinclude_default_template" is deprecated since Symfony 4.3, use "fragments.hinclude_default_template" instead.')->defaultNull()->end()
614615
->scalarNode('cache')->end()
615616
->arrayNode('form')
616617
->addDefaultsIfNotSet()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
487487

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

491496
$loader->load('fragment_listener.xml');
492497
$container->setParameter('fragment.path', $config['path']);

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<xsd:complexType name="fragments">
7070
<xsd:attribute name="enabled" type="xsd:boolean" />
7171
<xsd:attribute name="path" type="xsd:string" />
72+
<xsd:attribute name="hinclude-default-template" type="xsd:string" />
7273
</xsd:complexType>
7374

7475
<xsd:complexType name="web_link">

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ protected static function getBundleDefaultConfig()
209209
'fragments' => [
210210
'enabled' => false,
211211
'path' => '/_fragment',
212+
'hinclude_default_template' => null,
212213
],
213214
'profiler' => [
214215
'enabled' => false,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'templating' => [
5+
'cache' => '/path/to/cache',
6+
'engines' => ['php', 'twig'],
7+
'loader' => ['loader.foo', 'loader.bar'],
8+
'form' => [
9+
'resources' => ['theme1', 'theme2'],
10+
],
11+
'hinclude_default_template' => 'global_hinclude_template',
12+
],
13+
'assets' => null,
14+
'fragments' => [
15+
'enabled' => true,
16+
'hinclude_default_template' => 'global_hinclude_template',
17+
],
18+
]);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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:esi enabled="true" />
11+
<framework:ssi enabled="true" />
12+
<framework:assets />
13+
<framework:templating cache="/path/to/cache" hinclude-default-template="global_hinclude_template">
14+
<framework:loader>loader.foo</framework:loader>
15+
<framework:loader>loader.bar</framework:loader>
16+
<framework:engine>php</framework:engine>
17+
<framework:engine>twig</framework:engine>
18+
<framework:form>
19+
<framework:resource>theme1</framework:resource>
20+
<framework:resource>theme2</framework:resource>
21+
</framework:form>
22+
</framework:templating>
23+
</framework:config>
24+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
framework:
2+
fragments:
3+
enabled: true
4+
hinclude_default_template: global_hinclude_template
5+
templating:
6+
engines: [php, twig]
7+
loader: [loader.foo, loader.bar]
8+
cache: /path/to/cache
9+
form:
10+
resources: [theme1, theme2]
11+
hinclude_default_template: global_hinclude_template
12+
assets: ~

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ public function testEsiDisabled()
159159
$this->assertFalse($container->hasDefinition('esi'));
160160
}
161161

162+
/**
163+
* @expectedException \LogicException
164+
*/
165+
public function testAmbiguousWhenBothTemplatingAndFragments()
166+
{
167+
$this->createContainerFromFile('template_and_fragments');
168+
}
169+
162170
public function testSsi()
163171
{
164172
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)
0