‪TYPO3CMS  10.4
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 TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

string $tagName = 'select'
 
mixed $selectedValue
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
TYPO3 CMS Extbase Configuration ConfigurationManagerInterface $configurationManager
 
bool $respectSubmittedDataValue = false
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
TYPO3 CMS Extbase Persistence 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 94 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

Reimplemented in TYPO3\CMS\Belog\ViewHelpers\Form\TranslateLabelSelectViewHelper.

Definition at line 229 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

Definition at line 327 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 a s selected; FALSE otherwise

Definition at line 285 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 (   $value,
  $label,
  $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 or not to add selected attribute
Returns
‪string the rendered option tag

Definition at line 350 of file SelectViewHelper.php.

References $output.

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

◆ renderOptionTags()

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

Render the option tags.

Parameters
array$options‪the options for the form.
Returns
‪string rendered tags.

Definition at line 214 of file SelectViewHelper.php.

References $output, TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\isSelected(), and TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\renderOptionTag().

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

◆ renderPrependOptionTag()

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

Render prepended option tag

Returns
‪string rendered prepended empty option

Definition at line 197 of file SelectViewHelper.php.

References $output, and TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper\renderOptionTag().

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

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 98 of file SelectViewHelper.php.