From 0a658c6eef6b74e64193b6d89bd6cde7a90f78fe Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 19 Sep 2017 13:13:19 -0400 Subject: [PATCH] Add exclusive Twig namespace for bundles path --- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 1 + .../TwigBundle/DependencyInjection/TwigExtension.php | 7 +++++++ .../Tests/DependencyInjection/TwigExtensionTest.php | 1 + 3 files changed, 9 insertions(+) diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index 8ba6647306..bdf357181f 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 3.4.0 ----- + * added exclusive Twig namespace only for root bundles * deprecated `Symfony\Bundle\TwigBundle\Command\DebugCommand`, use `Symfony\Bridge\Twig\Command\DebugCommand` instead * deprecated relying on the `ContainerAwareInterface` implementation for `Symfony\Bundle\TwigBundle\Command\LintCommand` * added option to configure default path templates (via `default_path`) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index d4450f531c..4123ad7c66 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -130,6 +130,13 @@ class TwigExtension extends Extension foreach ($bundle['paths'] as $path) { $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace)); } + + // add exclusive namespace for root bundles only + // to override a bundle template that also extends itself + if (count($bundle['paths']) > 0 && 0 === count($bundle['parents'])) { + // the last path must be the bundle views directory + $twigFilesystemLoaderDefinition->addMethodCall('addPath', array(end($bundle['paths']), '!'.$namespace)); + } } if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) { diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 9d47948d67..2faaaa38fc 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -198,6 +198,7 @@ class TwigExtensionTest extends TestCase array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'), array(__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'), array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'), + array(realpath(__DIR__.'/../..').'/Resources/views', '!Twig'), array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'), array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'), array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'),