Skip to content

Commit

Permalink
bug #5764 Fix passing TranslatableInterface Choices to ChoiceField (A…
Browse files Browse the repository at this point in the history
…munak)

This PR was merged into the 4.x branch.

Discussion
----------

Fix passing TranslatableInterface Choices to ChoiceField

The code checking whether a choice should be passed "untouched" because it already is Translatable (from #5066) is always false because it checks against the wrong variable. This results in the actual TranslatableMessage being thrown away.

Here `$selectedValue` is always an array key, so a string; the intention was probably to check against `$selectedLabel`.

Commits
-------

5fae8a6 Fix passing TranslatableInterface Choices to ChoiceConfigurator
  • Loading branch information
javiereguiluz committed May 23, 2023
2 parents 0eaa155 + 5fae8a6 commit 3af388b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Field/Configurator/ChoiceConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
$flippedChoices = $areChoicesTranslatable ? $choices : array_flip($this->flatten($choices));
foreach ((array) $fieldValue as $selectedValue) {
if (null !== $selectedLabel = $flippedChoices[$selectedValue] ?? null) {
if ($selectedValue instanceof TranslatableInterface) {
$choiceMessage = $selectedValue;
if ($selectedLabel instanceof TranslatableInterface) {
$choiceMessage = $selectedLabel;
} else {
$choiceMessage = t(
$selectedLabel,
Expand Down

0 comments on commit 3af388b

Please sign in to comment.