Skip to content

Commit

Permalink
[TwigBundle] removed the extensions setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 11, 2011
1 parent afa30d9 commit 9604573
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 32 deletions.
3 changes: 3 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ timeline closely anyway.
beta4 to beta5
--------------

* The `extensions` setting for Twig has been removed. There is now only one
way to register Twig extensions, via the `twig.extension` tag.

* The stack of Monolog handlers now bubbles the records by default. To stop
the propagation you need to configure the bubbling explicitly.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,13 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('twig');

$this->addExtensionsSection($rootNode);
$this->addFormSection($rootNode);
$this->addGlobalsSection($rootNode);
$this->addTwigOptions($rootNode);

return $treeBuilder;
}

private function addExtensionsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->fixXmlConfig('extension')
->children()
->arrayNode('extensions')
->prototype('scalar')->end()
->end()
->end()
;
}

private function addFormSection(ArrayNodeDefinition $rootNode)
{
$rootNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public function load(array $configs, ContainerBuilder $container)
}
}

if (!empty($config['extensions'])) {
foreach ($config['extensions'] as $id) {
$container->getDefinition($id)->addTag('twig.extension');
}
}

unset(
$config['form'],
$config['globals'],
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<parameter key="twig.extension.routing.class">Symfony\Bridge\Twig\Extension\RoutingExtension</parameter>
<parameter key="twig.extension.yaml.class">Symfony\Bridge\Twig\Extension\YamlExtension</parameter>
<parameter key="twig.extension.form.class">Symfony\Bridge\Twig\Extension\FormExtension</parameter>
<parameter key="twig.extension.text.class">Twig_Extensions_Extension_Text</parameter>
<parameter key="twig.extension.debug.class">Twig_Extensions_Extension_Debug</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -76,9 +74,5 @@
<tag name="twig.extension" />
<argument>%twig.form.resources%</argument>
</service>

<service id="twig.extension.text" class="%twig.extension.text.class%" public="false" />

<service id="twig.extension.debug" class="%twig.extension.debug.class%" public="false" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public function testLoadFullConfiguration($format)

$this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');

// Extensions
foreach (array('twig.extension.debug', 'twig.extension.text') as $id) {
$config = $container->getDefinition($id);
$this->assertEquals(array('twig.extension'), array_keys($config->getTags()), '->load() adds tags to extension definitions');
}

// Form resources
$resources = $container->getParameter('twig.form.resources');
$this->assertContains('div_layout.html.twig', $resources, '->load() includes default template for form resources');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function buildViewBottomUp(FormView $view, FormInterface $form)
public function getDefaultOptions(array $options)
{
return array(
'type' => 'file',
'type' => 'string',
);
}

Expand Down

5 comments on commit 9604573

@stof
Copy link
Member

@stof stof commented on 9604573 Jun 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no built-in way to enable these official extensions now ?

@olamedia
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one
13

  • way to register Twig extensions, via the twig.extension tag.

@stof
Copy link
Member

@stof stof commented on 9604573 Jun 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this setting was used to make it easy to register the extensions from the official Twig-extensions repository. Currently, this require the user to define a service himself, which is less easy (and btw, its behavior was to add a tag). What about having config settings to enable the debug extension and the text extension (but only these one as user-defined extension should use the tag).

@weaverryan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Fabien that it's odd to support 2 different ways of registering twig extensions: the extensions option for these 2 core extensions and the twig.extension tag otherwise. That being said, I agree with @stof that it's quite unfortunate that registering these two core extensions is much more work now. If we look at community bundles, we'll see that it's common to register a twig extension based on the presence of a semantic extension option.

Perhaps it's best added back, but with a different name to represent these being "core" or "extra" extensions that are packages specifically to just this bundle:

twig:
    debug_extension: true
    text_extension:  true

or

twig:
    extra_extensions:
        text:  true
        debug: true

Or maybe we create a separate bundle - TwigExtraBundle - and then have it be responsible for the twig-extensions. That would create a degree of separation, and we could probably do more inside that bundle, since - even if it were included in the SE - it wouldn't be core.

I don't want to make more work (which I kind of am), but food for thought.

@mvrhov
Copy link

@mvrhov mvrhov commented on 9604573 Jun 15, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just nuisance for early adopters and if you are unused to defining services in yaml. The quickest fix would be to just document this in twig section of the docs. I've done it myself but I really don't have an idea into which specific section I should put it.
e.g

services:
    twig.extension.debug:
        class: Twig_Extensions_Extension_Debug
        tag: twig.extension

Please sign in to comment.