Skip to content

Commit cd0ba95

Browse files
Merge pull request #664 from devmes/bugfix/663
[BUGFIX] Support multiple values in SelectViewHelper
2 parents 225416f + 9cbe86c commit cd0ba95

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Classes/ViewHelpers/Form/SelectViewHelper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SelectViewHelper extends AbstractFormFieldViewHelper
3232
public function initialize(): void
3333
{
3434
parent::initialize();
35-
$this->tag->addAttribute('data-selected-value', $this->getSelectedValue());
35+
$this->tag->addAttribute('data-selected-value', is_array($this->getSelectedValue()) ? implode(',', $this->getSelectedValue()) : $this->getSelectedValue());
3636
}
3737

3838
public function initializeArguments(): void
@@ -313,7 +313,6 @@ protected function isSelected(mixed $value): bool
313313
*/
314314
protected function getSelectedValue()
315315
{
316-
$selectedValues = null;
317316
$this->setRespectSubmittedDataValue(true);
318317
$value = $this->getValueAttribute();
319318
if (!is_array($value) && !$value instanceof \Traversable) {
@@ -322,6 +321,10 @@ protected function getSelectedValue()
322321
return $selectedValues;
323322
}
324323
}
324+
$selectedValues = [];
325+
foreach ($value as $selectedValueElement) {
326+
$selectedValues[] = $this->getOptionValueScalar($selectedValueElement);
327+
}
325328

326329
// set preselection from TypoScript
327330
if (! $this->renderingContext instanceof RenderingContext) {

0 commit comments

Comments
 (0)