2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
78 parent::initializeArguments();
82 $this->
registerTagAttribute(
'disabled',
'string',
'Specifies that the input element should be disabled when the page loads');
83 $this->
registerArgument(
'options',
'array',
'Associative array with internal IDs as key, and the values are displayed in the select box',
true);
84 $this->
registerArgument(
'optionValueField',
'string',
'If specified, will call the appropriate getter on each object to determine the value.');
85 $this->
registerArgument(
'optionLabelField',
'string',
'If specified, will call the appropriate getter on each object to determine the label.');
86 $this->
registerArgument(
'sortByOptionLabel',
'boolean',
'If true, List will be sorted by label.',
false,
false);
87 $this->
registerArgument(
'selectAllByDefault',
'boolean',
'If specified options are selected if none was set before.',
false,
false);
88 $this->
registerArgument(
'errorClass',
'string',
'CSS class to set if there are errors for this view helper',
false,
'f3-form-error');
89 $this->
registerArgument(
'prependOptionLabel',
'string',
'If specified, will provide an option at first position with the specified label.');
90 $this->
registerArgument(
'prependOptionValue',
'string',
'If specified, will provide an option at first position with the specified value.');
105 $this->tag->addAttribute(
'name', $name);
107 if (empty($options)) {
108 $options = array(
'' =>
'');
117 if ($this->
hasArgument(
'multiple') && $this->arguments[
'multiple'] !==
'') {
119 for ($i = 0; $i < count($options); $i++) {
125 $content .= $this->tag->render();
139 $value = $this->
hasArgument(
'prependOptionValue') ? $this->arguments[
'prependOptionValue'] :
'';
140 $label = $this->arguments[
'prependOptionLabel'];
143 foreach ($options as $value => $label) {
157 if (!is_array($this->arguments[
'options']) && !$this->arguments[
'options'] instanceof \Traversable) {
161 $optionsArgument = $this->arguments[
'options'];
162 foreach ($optionsArgument as $key => $value) {
163 if (is_object($value) || is_array($value)) {
165 $key = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments[
'optionValueField']);
166 if (is_object($key)) {
167 if (method_exists($key,
'__toString')) {
170 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Identifying value for object of class "' . get_class($value) .
'" was an object.', 1247827428);
174 }
elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
175 $key = $this->persistenceManager->getIdentifierByObject($value);
176 }
elseif (method_exists($value,
'__toString')) {
177 $key = (string)$value;
179 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'No identifying value for object of class "' . get_class($value) .
'" found.', 1247826696);
182 $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments[
'optionLabelField']);
183 if (is_object($value)) {
184 if (method_exists($value,
'__toString')) {
185 $value = (string)$value;
187 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);
190 }
elseif (method_exists($value,
'__toString')) {
191 $value = (string)$value;
193 }
elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
194 $value = $this->persistenceManager->getIdentifierByObject($value);
197 $options[$key] = $value;
199 if ($this->arguments[
'sortByOptionLabel']) {
200 asort($options, SORT_LOCALE_STRING);
218 if (is_null(
$selectedValue) && $this->arguments[
'selectAllByDefault'] ===
true) {
236 if (!is_array($value) && !$value instanceof \Traversable) {
239 $selectedValues = array();
240 foreach ($value as $selectedValueElement) {
243 return $selectedValues;
254 if (is_object($valueElement)) {
256 return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($valueElement, $this->arguments[
'optionValueField']);
259 if ($this->persistenceManager->getIdentifierByObject($valueElement) !== null) {
260 return $this->persistenceManager->getIdentifierByObject($valueElement);
262 return (
string)$valueElement;
266 return $valueElement;
280 $output =
'<option value="' . htmlspecialchars($value) .
'"';
282 $output .=
' selected="selected"';
284 $output .=
'>' . htmlspecialchars($label) .
'</option>';