Skip to content

Commit 67a4885

Browse files
committed
bug symfony#24608 Adding the Form default theme files to be warmed up in Twig's cache (weaverryan)
This PR was merged into the 2.8 branch. Discussion ---------- Adding the Form default theme files to be warmed up in Twig's cache | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | not needed Hiya guys! So..... during a Symfony Live workshop, we found out that the form theme Twig templates are *not* included in the Twig cache warmup process. This fixes that. I believe this is the only "weird" case where we use a Twig template that is not in a bundle and also not added to Twig as a proper namespaces. I tested this on a 2.8 project. Before the patch, the form theme templates were not warmed up. After, they are warmed up. Booya. Cheers! Commits ------- 2ef619f Adding the Form default theme files to be warmed up in Twig's cache
2 parents 5f0a704 + 2ef619f commit 67a4885

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ public function process(ContainerBuilder $container)
4545
if ($container->has('form.extension')) {
4646
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
4747
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
48-
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
48+
49+
$coreThemePath = dirname(dirname($reflClass->getFileName())).'/Resources/views/Form';
50+
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array($coreThemePath));
51+
52+
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
53+
$paths[$coreThemePath] = null;
54+
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
55+
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
4956
}
5057

5158
if ($container->has('fragment.handler')) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function load(array $configs, ContainerBuilder $container)
8989
}
9090
}
9191

92+
// paths are modified in ExtensionPass if forms are enabled
9293
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']);
9394
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
9495

0 commit comments

Comments
 (0)