33 $this->registerUniversalTagAttributes();
34 $this->registerArgument(
'selected',
'boolean',
'If set, overrides automatic detection of selected state for this option.');
35 $this->registerArgument(
'additionalAttributes',
'array',
'Additional tag attributes. They will be added directly to the resulting HTML tag.');
36 $this->registerArgument(
'data',
'array',
'Additional data-* attributes. They will each be added with a "data-" prefix.');
37 $this->registerTagAttribute(
'value',
'mixed',
'Value to be inserted in HTML tag - must be convertible to string!');
45 if ($this->arguments[
'selected'] ?? $this->
isValueSelected($this->arguments[
'value'])) {
46 $this->tag->addAttribute(
'selected',
'selected');
48 $childContent = $this->renderChildren();
49 $this->tag->setContent($childContent);
50 $value = $this->arguments[
'value'] ?? $childContent;
51 $this->tag->addAttribute(
'value', $value);
52 $parentRequestedFormTokenFieldName = $this->renderingContext->getViewHelperVariableContainer()->get(
53 SelectViewHelper::class,
54 'registerFieldNameForFormTokenGeneration'
56 if ($parentRequestedFormTokenFieldName) {
62 return $this->tag->render();
71 $selectedValue = $this->renderingContext->getViewHelperVariableContainer()->get(SelectViewHelper::class,
'selectedValue');
72 if (is_array($selectedValue)) {
73 return in_array($value, $selectedValue);
75 if ($selectedValue instanceof \Iterator) {
76 return in_array($value, iterator_to_array($selectedValue));
78 return $value == $selectedValue;