Skip to content

Commit e5e9b90

Browse files
dotdeviokbond
authored andcommitted
[Autocomplete] Reset form state on each request for applications that reuse the Symfony application between requests
1 parent 58a9b73 commit e5e9b90

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Autocomplete/src/DependencyInjection/AutocompleteFormTypePass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private function processEntityAutocompleteFieldTag(ContainerBuilder $container)
4747
$wrappedDefinition = (new ChildDefinition('ux.autocomplete.wrapped_entity_type_autocompleter'))
4848
// the "formType" string
4949
->replaceArgument(0, $serviceDefinition->getClass())
50-
->addTag(self::ENTITY_AUTOCOMPLETER_TAG, ['alias' => $alias]);
50+
->addTag(self::ENTITY_AUTOCOMPLETER_TAG, ['alias' => $alias])
51+
->addTag('kernel.reset', ['method' => 'reset']);
5152
$container->setDefinition('ux.autocomplete.wrapped_entity_type_autocompleter.'.$alias, $wrappedDefinition);
5253
}
5354
}

src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\FormInterface;
2020
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
2121
use Symfony\Component\PropertyAccess\PropertyPathInterface;
22+
use Symfony\Contracts\Service\ResetInterface;
2223
use Symfony\UX\Autocomplete\Doctrine\EntityMetadata;
2324
use Symfony\UX\Autocomplete\Doctrine\EntityMetadataFactory;
2425
use Symfony\UX\Autocomplete\Doctrine\EntitySearchUtil;
@@ -29,7 +30,7 @@
2930
*
3031
* @internal
3132
*/
32-
final class WrappedEntityTypeAutocompleter implements OptionsAwareEntityAutocompleterInterface
33+
final class WrappedEntityTypeAutocompleter implements OptionsAwareEntityAutocompleterInterface, ResetInterface
3334
{
3435
private ?FormInterface $form = null;
3536
private ?EntityMetadata $entityMetadata = null;
@@ -188,4 +189,10 @@ public function setOptions(array $options): void
188189

189190
$this->options = $options;
190191
}
192+
193+
public function reset(): void
194+
{
195+
unset($this->form);
196+
$this->form = null;
197+
}
191198
}

0 commit comments

Comments
 (0)