Skip to content

Commit

Permalink
feature #30959 [FrameworkBundle] [TwigBundle] Move the hinclude key a…
Browse files Browse the repository at this point in the history
…way 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
  • Loading branch information
fabpot committed Apr 8, 2019
2 parents 9b9d416 + 4f39339 commit 35b1ded
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private function addFragmentsSection(ArrayNodeDefinition $rootNode)
->info('fragments configuration')
->canBeEnabled()
->children()
->scalarNode('hinclude_default_template')->defaultNull()->end()
->scalarNode('path')->defaultValue('/_fragment')->end()
->end()
->end()
Expand Down Expand Up @@ -610,7 +611,7 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->then(function () { return ['enabled' => false, 'engines' => false]; })
->end()
->children()
->scalarNode('hinclude_default_template')->defaultNull()->end()
->scalarNode('hinclude_default_template')->setDeprecated('Setting "templating.hinclude_default_template" is deprecated since Symfony 4.3, use "fragments.hinclude_default_template" instead.')->defaultNull()->end()
->scalarNode('cache')->end()
->arrayNode('form')
->addDefaultsIfNotSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ 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']) {
throw new \LogicException('You cannot set both "templating.hinclude_default_template" and "fragments.hinclude_default_template", please only use "fragments.hinclude_default_template".');
}

$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);

$loader->load('fragment_listener.xml');
$container->setParameter('fragment.path', $config['path']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<xsd:complexType name="fragments">
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="hinclude-default-template" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="web_link">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ protected static function getBundleDefaultConfig()
'fragments' => [
'enabled' => false,
'path' => '/_fragment',
'hinclude_default_template' => null,
],
'profiler' => [
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$container->loadFromExtension('framework', [
'templating' => [
'cache' => '/path/to/cache',
'engines' => ['php', 'twig'],
'loader' => ['loader.foo', 'loader.bar'],
'form' => [
'resources' => ['theme1', 'theme2'],
],
'hinclude_default_template' => 'global_hinclude_template',
],
'assets' => null,
'fragments' => [
'enabled' => true,
'hinclude_default_template' => 'global_hinclude_template',
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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:esi enabled="true" />
<framework:ssi enabled="true" />
<framework:assets />
<framework:templating cache="/path/to/cache" hinclude-default-template="global_hinclude_template">
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
<framework:engine>php</framework:engine>
<framework:engine>twig</framework:engine>
<framework:form>
<framework:resource>theme1</framework:resource>
<framework:resource>theme2</framework:resource>
</framework:form>
</framework:templating>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
framework:
fragments:
enabled: true
hinclude_default_template: global_hinclude_template
templating:
engines: [php, twig]
loader: [loader.foo, loader.bar]
cache: /path/to/cache
form:
resources: [theme1, theme2]
hinclude_default_template: global_hinclude_template
assets: ~
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ public function testEsiDisabled()
$this->assertFalse($container->hasDefinition('esi'));
}

/**
* @expectedException \LogicException
*/
public function testAmbiguousWhenBothTemplatingAndFragments()
{
$this->createContainerFromFile('template_and_fragments');
}

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

0 comments on commit 35b1ded

Please sign in to comment.