77 parent::initializeArguments();
81 $this->
registerTagAttribute(
'disabled',
'string',
'Specifies that the input element should be disabled when the page loads');
82 $this->
registerArgument(
'options',
'array',
'Associative array with internal IDs as key, and the values are displayed in the select box', TRUE);
83 $this->
registerArgument(
'optionValueField',
'string',
'If specified, will call the appropriate getter on each object to determine the value.');
84 $this->
registerArgument(
'optionLabelField',
'string',
'If specified, will call the appropriate getter on each object to determine the label.');
85 $this->
registerArgument(
'sortByOptionLabel',
'boolean',
'If true, List will be sorted by label.', FALSE, FALSE);
86 $this->
registerArgument(
'selectAllByDefault',
'boolean',
'If specified options are selected if none was set before.', FALSE, FALSE);
87 $this->
registerArgument(
'errorClass',
'string',
'CSS class to set if there are errors for this view helper', FALSE,
'f3-form-error');
88 $this->
registerArgument(
'prependOptionLabel',
'string',
'If specified, will provide an option at first position with the specified label.');
89 $this->
registerArgument(
'prependOptionValue',
'string',
'If specified, will provide an option at first position with the specified value.');
103 $this->tag->addAttribute(
'name', $name);
105 if (empty($options)) {
106 $options = array(
'' =>
'');
114 if ($this->
hasArgument(
'multiple') && $this->arguments[
'multiple'] !==
'') {
116 for ($i = 0; $i < count($options); $i++) {
122 $content .= $this->tag->render();
135 $value = $this->
hasArgument(
'prependOptionValue') ? $this->arguments[
'prependOptionValue'] :
'';
136 $label = $this->arguments[
'prependOptionLabel'];
139 foreach ($options as $value => $label) {
141 $output .= $this->
renderOptionTag($value, $label, $isSelected) . chr(10);
152 if (!is_array($this->arguments[
'options']) && !$this->arguments[
'options'] instanceof \Traversable) {
156 $optionsArgument = $this->arguments[
'options'];
157 foreach ($optionsArgument as $key => $value) {
158 if (is_object($value)) {
161 if (is_object($key)) {
162 if (method_exists($key,
'__toString')) {
163 $key = (string) $key;
165 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Identifying value for object of class "' . get_class($value) .
'" was an object.', 1247827428);
169 } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
170 $key = $this->persistenceManager->getIdentifierByObject($value);
171 } elseif (method_exists($value,
'__toString')) {
172 $key = (string) $value;
174 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'No identifying value for object of class "' . get_class($value) .
'" found.', 1247826696);
178 if (is_object($value)) {
179 if (method_exists($value,
'__toString')) {
180 $value = (string) $value;
182 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);
185 } elseif (method_exists($value,
'__toString')) {
186 $value = (string) $value;
188 } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
189 $value = $this->persistenceManager->getIdentifierByObject($value);
192 $options[$key] = $value;
194 if ($this->arguments[
'sortByOptionLabel']) {
195 asort($options, SORT_LOCALE_STRING);
212 if (is_null(
$selectedValue) && $this->arguments[
'selectAllByDefault'] === TRUE) {
228 if (!is_array($value) && !$value instanceof \Traversable) {
231 $selectedValues = array();
232 foreach ($value as $selectedValueElement) {
235 return $selectedValues;
245 if (is_object($valueElement)) {
247 return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($valueElement, $this->arguments[
'optionValueField']);
250 if ($this->persistenceManager->getIdentifierByObject($valueElement) !== NULL) {
251 return $this->persistenceManager->getIdentifierByObject($valueElement);
253 return (
string) $valueElement;
257 return $valueElement;
270 $output =
'<option value="' . htmlspecialchars($value) .
'"';
272 $output .=
' selected="selected"';
274 $output .=
'>' . htmlspecialchars($label) .
'</option>';
hasArgument($argumentName)
registerTagAttribute($name, $type, $description, $required=FALSE, $default=NULL)
registerArgument($name, $type, $description, $required=FALSE, $defaultValue=NULL)
static getPropertyPath($subject, $propertyPath)
registerUniversalTagAttributes()