From 9cbe86c13372560fb769b0f9fe5ebe6c4fd32d97 Mon Sep 17 00:00:00 2001 From: Devid Messner Date: Wed, 24 Sep 2025 15:28:03 +0200 Subject: [PATCH] [BUGFIX] Support multiple values in SelectViewHelper The SelectViewHelper in v13.0.0 provided a `multiple` attribute, but handling of multiple selected values was not working. This commit fixes the issue by correctly reading and displaying multiple values. Resolves: #663 --- Classes/ViewHelpers/Form/SelectViewHelper.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Classes/ViewHelpers/Form/SelectViewHelper.php b/Classes/ViewHelpers/Form/SelectViewHelper.php index 3160f5bf7..14c9dc2a5 100644 --- a/Classes/ViewHelpers/Form/SelectViewHelper.php +++ b/Classes/ViewHelpers/Form/SelectViewHelper.php @@ -32,7 +32,7 @@ class SelectViewHelper extends AbstractFormFieldViewHelper public function initialize(): void { parent::initialize(); - $this->tag->addAttribute('data-selected-value', $this->getSelectedValue()); + $this->tag->addAttribute('data-selected-value', is_array($this->getSelectedValue()) ? implode(',', $this->getSelectedValue()) : $this->getSelectedValue()); } public function initializeArguments(): void @@ -313,7 +313,6 @@ protected function isSelected(mixed $value): bool */ protected function getSelectedValue() { - $selectedValues = null; $this->setRespectSubmittedDataValue(true); $value = $this->getValueAttribute(); if (!is_array($value) && !$value instanceof \Traversable) { @@ -322,6 +321,10 @@ protected function getSelectedValue() return $selectedValues; } } + $selectedValues = []; + foreach ($value as $selectedValueElement) { + $selectedValues[] = $this->getOptionValueScalar($selectedValueElement); + } // set preselection from TypoScript if (! $this->renderingContext instanceof RenderingContext) {