‪TYPO3CMS  ‪main
TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper:
TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper

Public Member Functions

 initializeArguments ()
 
 render ()
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
 injectConfigurationManager (ConfigurationManagerInterface $configurationManager)
 
 getRespectSubmittedDataValue ()
 
 setRespectSubmittedDataValue (bool $respectSubmittedDataValue)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
 injectPersistenceManager (PersistenceManagerInterface $persistenceManager)
 

Protected Member Functions

 renderPrependOptionTag ()
 
 renderOptionTags (array $options)
 
array getOptions ()
 
bool isSelected ($value)
 
mixed getSelectedValue ()
 
string getOptionValueScalar ($valueElement)
 
string renderOptionTag (string $value, string $label, bool $isSelected)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
 getName ()
 
RequestInterface getRequest ()
 
 getNameWithoutPrefix ()
 
mixed getValueAttribute ()
 
mixed getValueFromSubmittedFormData ($value)
 
mixed convertToPlainValue ($value)
 
 hasMappingErrorOccurred ()
 
mixed getLastSubmittedFormData ()
 
 addAdditionalIdentityPropertiesIfNeeded ()
 
mixed getPropertyValue ()
 
 isObjectAccessorMode ()
 
 setErrorClassAttribute ()
 
 getMappingResultsForProperty ()
 
 renderHiddenFieldForEmptyValue ()
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
 prefixFieldName (string $fieldName)
 
string renderHiddenIdentityField (?object $object, ?string $name)
 
 registerFieldNameForFormTokenGeneration (string $fieldName)
 

Protected Attributes

string $tagName = 'select'
 
mixed $selectedValue
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
ConfigurationManagerInterface $configurationManager
 
bool $respectSubmittedDataValue = false
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
PersistenceManagerInterface $persistenceManager
 

Detailed Description

This ViewHelper generates a :html:<select> dropdown list for the use with a form.

Basic usage

The most straightforward way is to supply an associative array as the options parameter. The array key is used as option key, and the value is used as human-readable name.

Basic usage::

<f:form.select name="paymentOptions" options="{payPal: 'PayPal International Services', visa: 'VISA Card'}" />

Pre select a value

To pre select a value, set value to the option key which should be selected. Default value::

<f:form.select name="paymentOptions" options="{payPal: 'PayPal International Services', visa: 'VISA Card'}" value="visa" />

Generates a dropdown box like above, except that "VISA Card" is selected.

If the select box is a multi-select box :html:multiple="1", then "value" can be an array as well.

Custom options and option group rendering

Child nodes can be used to create a completely custom set of :html:<option> and :html:<optgroup> tags in a way compatible with the HMAC generation. To do so, leave out the options argument and use child ViewHelpers:

Custom options and optgroup::

<f:form.select name="myproperty"> <f:form.select.option value="1">Option one</f:form.select.option> <f:form.select.option value="2">Option two</f:form.select.option> <f:form.select.optgroup> <f:form.select.option value="3">Grouped option one</f:form.select.option> <f:form.select.option value="4">Grouped option twi</f:form.select.option> </f:form.select.optgroup> </f:form.select>

.. note:: Do not use vanilla :html:<option> or :html:<optgroup> tags! They will invalidate the HMAC generation!

Usage on domain objects

If you want to output domain objects, you can just pass them as array into the options parameter. To define what domain object value should be used as option key, use the optionValueField variable. Same goes for optionLabelField. If neither is given, the Identifier (UID/uid) and the :php:__toString() method are tried as fallbacks.

If the optionValueField variable is set, the getter named after that value is used to retrieve the option key. If the optionLabelField variable is set, the getter named after that value is used to retrieve the option value.

If the prependOptionLabel variable is set, an option item is added in first position, bearing an empty string or - if provided, the value of the prependOptionValue variable as value.

Domain objects::

<f:form.select name="users" options="{userArray}" optionValueField="id" optionLabelField="firstName" />

In the above example, the userArray is an array of "User" domain objects, with no array key specified.

So, in the above example, the method :php:$user->getId() is called to retrieve the key, and :php:$user->getFirstName() to retrieve the displayed value of each entry.

The value property now expects a domain object, and tests for object equivalence.

Definition at line 96 of file SelectViewHelper.php.

Member Function Documentation

◆ getOptions()

array TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::getOptions ( )
protected

Render the option tags.

Returns
‪array An associative array of options, key will be the value of the option tag

Definition at line 218 of file SelectViewHelper.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyPath().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\render().

◆ getOptionValueScalar()

string TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::getOptionValueScalar (   $valueElement)
protected

Get the option value for an object

Parameters
mixed$valueElement
Returns
‪string
Todo:
‪: Does not always return string ...

Definition at line 330 of file SelectViewHelper.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyPath().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\getSelectedValue().

◆ getSelectedValue()

◆ initializeArguments()

TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::initializeArguments ( )

◆ isSelected()

bool TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::isSelected (   $value)
protected

Render the option tags.

Parameters
mixed$value‪Value to check for
Returns
‪bool True if the value should be marked as selected.

Definition at line 288 of file SelectViewHelper.php.

References TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\$selectedValue, and TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\getSelectedValue().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\renderOptionTags().

◆ render()

◆ renderOptionTag()

string TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::renderOptionTag ( string  $value,
string  $label,
bool  $isSelected 
)
protected

Render one option tag

Parameters
string$value‪value attribute of the option tag (will be escaped)
string$label‪content of the option tag (will be escaped)
bool$isSelected‪specifies whether to add selected attribute
Returns
‪string the rendered option tag

Definition at line 353 of file SelectViewHelper.php.

References $output.

Referenced by TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\renderOptionTags(), and TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\renderPrependOptionTag().

◆ renderOptionTags()

TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::renderOptionTags ( array  $options)
protected

◆ renderPrependOptionTag()

TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::renderPrependOptionTag ( )
protected

Member Data Documentation

◆ $selectedValue

mixed TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::$selectedValue
protected

◆ $tagName

string TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper::$tagName = 'select'
protected

Definition at line 100 of file SelectViewHelper.php.