Skip to content

Commit c89e1e0

Browse files
committed
reset Twig form theme resources between requests
1 parent 7b43f0f commit c89e1e0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2020
use Symfony\Component\DependencyInjection\Reference;
21+
use Symfony\Component\Form\AbstractRendererEngine;
2122
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2223
use Symfony\Component\Mailer\Mailer;
2324
use Symfony\Component\Translation\Translator;
25+
use Symfony\Contracts\Service\ResetInterface;
2426
use Twig\Extension\ExtensionInterface;
2527
use Twig\Extension\RuntimeExtensionInterface;
2628
use Twig\Loader\LoaderInterface;
@@ -40,6 +42,10 @@ public function load(array $configs, ContainerBuilder $container)
4042

4143
if (class_exists(\Symfony\Component\Form\Form::class)) {
4244
$loader->load('form.xml');
45+
46+
if (is_subclass_of(AbstractRendererEngine::class, ResetInterface::class)) {
47+
$container->getDefinition('twig.form.engine')->addTag('kernel.reset');
48+
}
4349
}
4450

4551
if (interface_exists(\Symfony\Component\Templating\EngineInterface::class)) {

src/Symfony/Component/Form/AbstractRendererEngine.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Contracts\Service\ResetInterface;
15+
1416
/**
1517
* Default implementation of {@link FormRendererEngineInterface}.
1618
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
19-
abstract class AbstractRendererEngine implements FormRendererEngineInterface
21+
abstract class AbstractRendererEngine implements FormRendererEngineInterface, ResetInterface
2022
{
2123
/**
2224
* The variable in {@link FormView} used as cache key.
@@ -197,4 +199,13 @@ private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $v
197199

198200
return false;
199201
}
202+
203+
public function reset(): void
204+
{
205+
$this->defaultThemes = [];
206+
$this->themes = [];
207+
$this->useDefaultThemes = [];
208+
$this->resources = [];
209+
$this->resourceHierarchyLevels = [];
210+
}
200211
}

0 commit comments

Comments
 (0)