2 namespace TYPO3\CMS\Form\ViewHelpers;
29 if (!is_array($this->arguments[
'options']) && !$this->arguments[
'options'] instanceof \Traversable) {
33 $optionsArgument = $this->arguments[
'options'];
34 foreach ($optionsArgument as $key => $value) {
35 if (is_string($key)) {
36 $options[$key][
'disabled'] = $value[
'disabled'];
37 $options[$key][
'isOptgroup'] =
true;
38 $optGroupOptions = $value[
'options'];
39 foreach ($optGroupOptions as $optionKey => $optionValue) {
40 $option = $this->
getOption($optionKey, $optionValue);
41 $options[$key][
'options'][key($option)] = current($option);
45 $options[key($option)] = current($option);
49 if ($this->arguments[
'sortByOptionLabel']) {
50 asort($options, SORT_LOCALE_STRING);
65 if (is_object($value) || is_array($value)) {
67 $key = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments[
'optionValueField']);
68 if (is_object($key)) {
69 if (method_exists($key,
'__toString')) {
72 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Identifying value for object of class "' . get_class($value) .
'" was an object.', 1247827428);
76 }
elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
77 $key = $this->persistenceManager->getIdentifierByObject($value);
78 }
elseif (method_exists($value,
'__toString')) {
79 $key = (string)$value;
81 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'No identifying value for object of class "' . get_class($value) .
'" found.', 1247826696);
84 $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments[
'optionLabelField']);
85 if (is_object($value)) {
86 if (method_exists($value,
'__toString')) {
87 $value = (string)$value;
89 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Label value for object of class "' . get_class($value) .
'" was an object without a __toString() method.', 1247827553);
92 }
elseif (method_exists($value,
'__toString')) {
93 $value = (string)$value;
95 }
elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
96 $value = $this->persistenceManager->getIdentifierByObject($value);
99 $option[$key] = $value;
113 $value = $this->
hasArgument(
'prependOptionValue') ? $this->arguments[
'prependOptionValue'] :
'';
114 $label = $this->arguments[
'prependOptionLabel'];
117 foreach ($options as $value => $label) {
119 isset($label[
'isOptgroup'])
120 && $label[
'isOptgroup'] ===
true
122 $output .=
'<optgroup label="' . htmlspecialchars($value) .
'"';
123 if ($label[
'disabled'] !== null) {
124 $output .=
' disabled="disabled"';
127 foreach ($label[
'options'] as $optionValue => $optionLabel) {
128 $isSelected = $this->
isSelected($optionValue);
129 $output .= $this->
renderOptionTag($optionValue, $optionLabel, $isSelected) . LF;
131 $output .=
' </optgroup>' . LF;