Skip to content

Commit

Permalink
bug #45909 [Form][TwigBundle] reset Twig form theme resources between…
Browse files Browse the repository at this point in the history
… requests (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form][TwigBundle] reset Twig form theme resources between requests

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45229
| License       | MIT
| Doc PR        |

Commits
-------

873a86e reset Twig form theme resources between requests
  • Loading branch information
fabpot committed Apr 1, 2022
2 parents bbcfb0c + 873a86e commit f0fde2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -18,9 +18,11 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Service\ResetInterface;
use Twig\Extension\ExtensionInterface;
use Twig\Extension\RuntimeExtensionInterface;
use Twig\Loader\LoaderInterface;
Expand All @@ -40,6 +42,12 @@ public function load(array $configs, ContainerBuilder $container)

if (class_exists(\Symfony\Component\Form\Form::class)) {
$loader->load('form.xml');

if (is_subclass_of(AbstractRendererEngine::class, ResetInterface::class)) {
$container->getDefinition('twig.form.engine')->addTag('kernel.reset', [
'method' => 'reset',
]);
}
}

if (interface_exists(\Symfony\Component\Templating\EngineInterface::class)) {
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/Form/AbstractRendererEngine.php
Expand Up @@ -11,12 +11,14 @@

namespace Symfony\Component\Form;

use Symfony\Contracts\Service\ResetInterface;

/**
* Default implementation of {@link FormRendererEngineInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class AbstractRendererEngine implements FormRendererEngineInterface
abstract class AbstractRendererEngine implements FormRendererEngineInterface, ResetInterface
{
/**
* The variable in {@link FormView} used as cache key.
Expand Down Expand Up @@ -197,4 +199,12 @@ private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $v

return false;
}

public function reset(): void
{
$this->themes = [];
$this->useDefaultThemes = [];
$this->resources = [];
$this->resourceHierarchyLevels = [];
}
}

0 comments on commit f0fde2f

Please sign in to comment.