Skip to content

Commit

Permalink
[Autocomplete] Reset form state on each request for applications that…
Browse files Browse the repository at this point in the history
… reuse the Symfony application between requests
  • Loading branch information
dotdevio authored and kbond committed Aug 31, 2024
1 parent 58a9b73 commit e5e9b90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private function processEntityAutocompleteFieldTag(ContainerBuilder $container)
$wrappedDefinition = (new ChildDefinition('ux.autocomplete.wrapped_entity_type_autocompleter'))
// the "formType" string
->replaceArgument(0, $serviceDefinition->getClass())
->addTag(self::ENTITY_AUTOCOMPLETER_TAG, ['alias' => $alias]);
->addTag(self::ENTITY_AUTOCOMPLETER_TAG, ['alias' => $alias])
->addTag('kernel.reset', ['method' => 'reset']);
$container->setDefinition('ux.autocomplete.wrapped_entity_type_autocompleter.'.$alias, $wrappedDefinition);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
use Symfony\Contracts\Service\ResetInterface;
use Symfony\UX\Autocomplete\Doctrine\EntityMetadata;
use Symfony\UX\Autocomplete\Doctrine\EntityMetadataFactory;
use Symfony\UX\Autocomplete\Doctrine\EntitySearchUtil;
Expand All @@ -29,7 +30,7 @@
*
* @internal
*/
final class WrappedEntityTypeAutocompleter implements OptionsAwareEntityAutocompleterInterface
final class WrappedEntityTypeAutocompleter implements OptionsAwareEntityAutocompleterInterface, ResetInterface
{
private ?FormInterface $form = null;
private ?EntityMetadata $entityMetadata = null;
Expand Down Expand Up @@ -188,4 +189,10 @@ public function setOptions(array $options): void

$this->options = $options;
}

public function reset(): void
{
unset($this->form);
$this->form = null;
}
}

0 comments on commit e5e9b90

Please sign in to comment.