Skip to content

Commit

Permalink
bug #5997 Fix finding selected enum value in choices (klkvsk)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Fix finding selected enum value in choices

Fix #5984

Commits
-------

dc6818a Fix finding selected enum value in choices
  • Loading branch information
javiereguiluz committed Nov 1, 2023
2 parents b5c9b7a + dc6818a commit 9064cc7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Field/Configurator/ChoiceConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9064cc7

Please sign in to comment.