From b5292d29fd51f1fc20dfd655a1ac764a70dad307 Mon Sep 17 00:00:00 2001 From: Yohann Tilotti Date: Mon, 11 Dec 2023 18:09:50 +0100 Subject: [PATCH] [Autocomplete] Fix choice_value bug --- .../src/Form/WrappedEntityTypeAutocompleter.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php b/src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php index 663a7ed80bc..546cf4b0151 100644 --- a/src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php +++ b/src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php @@ -99,7 +99,17 @@ public function getLabel(object $entity): string public function getValue(object $entity): string { - return $this->getEntityMetadata()->getIdValue($entity); + $choiceValue = $this->getFormOption('choice_value'); + + if (\is_string($choiceValue) || $choiceValue instanceof PropertyPathInterface) { + return $this->propertyAccessor->getValue($entity, $choiceValue); + } + + if ($choiceValue instanceof Cache\ChoiceValue) { + $choiceValue = $choiceValue->getOption(); + } + + return $choiceValue($entity); } public function isGranted(Security $security): bool