From dc6818a6a2f8f69c4493eb8f5938454f17d808d3 Mon Sep 17 00:00:00 2001 From: Misha Kulakovsky Date: Wed, 1 Nov 2023 13:02:05 +0000 Subject: [PATCH] Fix finding selected enum value in choices --- src/Field/Configurator/ChoiceConfigurator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Field/Configurator/ChoiceConfigurator.php b/src/Field/Configurator/ChoiceConfigurator.php index 03a6aad806..bea68d4c3d 100644 --- a/src/Field/Configurator/ChoiceConfigurator.php +++ b/src/Field/Configurator/ChoiceConfigurator.php @@ -107,6 +107,11 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c // Translatable choice don't need to get flipped $flippedChoices = $areChoicesTranslatable ? $choices : array_flip($this->flatten($choices)); foreach ((array) $fieldValue as $selectedValue) { + $selectedValue = match (true) { + $selectedValue instanceof \BackedEnum => $selectedValue->value, + $selectedValue instanceof \UnitEnum => $selectedValue->name, + default => $selectedValue + }; if (null !== $selectedLabel = $flippedChoices[$selectedValue] ?? null) { if ($selectedLabel instanceof TranslatableInterface) { $choiceMessage = $selectedLabel;