Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b8b8cd2

Browse filesBrowse files
committed
merged branch jfsimon/issue-6238 (PR #7373)
This PR was squashed before being merged into the master branch (closes #7373). Commits ------- e372183 [TwigBundle] Adds service check for extension loading Discussion ---------- [TwigBundle] Adds service check for extension loading This PR adds following checks: * `twig.extension.form` extension is loaded if `form.extension` service is defined * `twig.extension.trans` extension is loaded if `translator` service is defined | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #6238
2 parents 2453a58 + e372183 commit b8b8cd2
Copy full SHA for b8b8cd2

File tree

Expand file treeCollapse file tree

4 files changed

+37
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-5
lines changed
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
19+
*/
20+
class ExtensionPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container)
23+
{
24+
if ($container->has('form.extension')) {
25+
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
26+
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
27+
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
28+
}
29+
30+
if (false === $container->has('translator')) {
31+
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
32+
}
33+
}
34+
}

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public function load(array $configs, ContainerBuilder $container)
5757

5858
$container->setParameter('twig.form.resources', $config['form']['resources']);
5959

60-
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
61-
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
62-
6360
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
6461

6562
// register user-configured paths

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
</service>
5959

6060
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
61-
<tag name="twig.extension" />
6261
<argument type="service" id="translator" />
6362
</service>
6463

@@ -93,8 +92,8 @@
9392
<argument type="service" id="fragment.handler" />
9493
</service>
9594

95+
9696
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
97-
<tag name="twig.extension" />
9897
<argument type="service" id="twig.form.renderer" />
9998
</service>
10099

‎src/Symfony/Bundle/TwigBundle/TwigBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TwigBundle.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
1717
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
1818
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass;
19+
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
1920

2021
/**
2122
* Bundle.
@@ -28,6 +29,7 @@ public function build(ContainerBuilder $container)
2829
{
2930
parent::build($container);
3031

32+
$container->addCompilerPass(new ExtensionPass());
3133
$container->addCompilerPass(new TwigEnvironmentPass());
3234
$container->addCompilerPass(new TwigLoaderPass());
3335
$container->addCompilerPass(new ExceptionListenerPass());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.