TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
SelectViewHelper Class Reference
Inheritance diagram for SelectViewHelper:
AbstractFormFieldViewHelper AbstractFormViewHelper AbstractTagBasedViewHelper AbstractViewHelper TranslateLabelSelectViewHelper

Public Member Functions

 initializeArguments ()
 
 render ()
 
- Public Member Functions inherited from AbstractFormFieldViewHelper
 injectConfigurationManager (\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
 
 initializeArguments ()
 
 getRespectSubmittedDataValue ()
 
 setRespectSubmittedDataValue ($respectSubmittedDataValue)
 
- Public Member Functions inherited from AbstractFormViewHelper
 injectPersistenceManager (\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
 
- Public Member Functions inherited from AbstractTagBasedViewHelper
 __construct ()
 
 initializeArguments ()
 
 initialize ()
 
- Public Member Functions inherited from AbstractViewHelper
 setRenderingContext (\TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 prepareArguments ()
 

Protected Member Functions

 renderOptionTags ($options)
 
 getOptions ()
 
 isSelected ($value)
 
 getSelectedValue ()
 
 getOptionValueScalar ($valueElement)
 
 renderOptionTag ($value, $label, $isSelected)
 
- Protected Member Functions inherited from AbstractFormFieldViewHelper
 getName ()
 
 getRequest ()
 
 getNameWithoutPrefix ()
 
 getValueAttribute ()
 
 getValueFromSubmittedFormData ($value)
 
 convertToPlainValue ($value)
 
 hasMappingErrorOccurred ()
 
 getLastSubmittedFormData ()
 
 addAdditionalIdentityPropertiesIfNeeded ()
 
 getPropertyValue ()
 
 isObjectAccessorMode ()
 
 setErrorClassAttribute ()
 
 getMappingResultsForProperty ()
 
 renderHiddenFieldForEmptyValue ()
 
- Protected Member Functions inherited from AbstractFormViewHelper
 prefixFieldName ($fieldName)
 
 renderHiddenIdentityField ($object, $name)
 
 registerFieldNameForFormTokenGeneration ($fieldName)
 
- Protected Member Functions inherited from AbstractTagBasedViewHelper
 registerTagAttribute ($name, $type, $description, $required=false, $default=null)
 
 registerUniversalTagAttributes ()
 
- Protected Member Functions inherited from AbstractViewHelper
 callRenderMethod ()
 
 getLogger ()
 
 registerRenderMethodArguments ()
 

Protected Attributes

 $tagName = 'select'
 
 $selectedValue = null
 
- Protected Attributes inherited from AbstractFormFieldViewHelper
 $configurationManager
 
 $respectSubmittedDataValue = false
 
- Protected Attributes inherited from AbstractFormViewHelper
 $persistenceManager
 
- Protected Attributes inherited from AbstractTagBasedViewHelper
 $tagName = 'div'
 
 $tag
 
 $escapeOutput = false
 
- Protected Attributes inherited from AbstractViewHelper
 $controllerContext
 
 $objectManager
 

Detailed Description

This view helper generates a <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.

<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. <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 (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 <option> and <optgroup> tags in a way compatible with the HMAC generation. To do so, leave out the options argument and use child ViewHelpers: <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 <option> or <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 __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.

<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 $user->getId() is called to retrieve the key, and $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 78 of file SelectViewHelper.php.

Member Function Documentation

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

References ObjectAccess\getPropertyPath().

Referenced by SelectViewHelper\render().

getOptionValueScalar (   $valueElement)
protected

Get the option value for an object

Parameters
mixed$valueElement
Returns
string

Definition at line 294 of file SelectViewHelper.php.

Referenced by SelectViewHelper\getSelectedValue().

getSelectedValue ( )
protected

Retrieves the selected value(s)

Returns
mixed value string or an array of strings

Definition at line 274 of file SelectViewHelper.php.

References SelectViewHelper\getOptionValueScalar(), AbstractFormFieldViewHelper\getValueAttribute(), and AbstractFormFieldViewHelper\setRespectSubmittedDataValue().

Referenced by SelectViewHelper\isSelected(), and SelectViewHelper\render().

initializeArguments ( )
isSelected (   $value)
protected

Render the option tags.

Parameters
mixed$valueValue to check for
Returns
bool TRUE if the value should be marked a s selected; FALSE otherwise

Definition at line 253 of file SelectViewHelper.php.

References SelectViewHelper\$selectedValue, and SelectViewHelper\getSelectedValue().

Referenced by SelectViewHelper\renderOptionTags().

renderOptionTag (   $value,
  $label,
  $isSelected 
)
protected

Render one option tag

Parameters
string$valuevalue attribute of the option tag (will be escaped)
string$labelcontent of the option tag (will be escaped)
bool$isSelectedspecifies wheter or not to add selected attribute
Returns
string the rendered option tag

Definition at line 320 of file SelectViewHelper.php.

Referenced by SelectViewHelper\renderOptionTags().

renderOptionTags (   $options)
protected

Render the option tags.

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

Definition at line 177 of file SelectViewHelper.php.

References SelectViewHelper\isSelected(), and SelectViewHelper\renderOptionTag().

Referenced by SelectViewHelper\render().

Member Data Documentation

$selectedValue = null
protected

Definition at line 88 of file SelectViewHelper.php.

Referenced by SelectViewHelper\isSelected().

$tagName = 'select'
protected

Definition at line 83 of file SelectViewHelper.php.