PHP Class Neos\FluidAdaptor\ViewHelpers\Form\SelectViewHelper

**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 array value is used as human-readable name. To pre-select a value, set "value" to the option key which should be selected. If the select box is a multi-select box (multiple="true"), then "value" can be an array as well. **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 (UUID/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 specified - the value of the prependOptionValue variable as value. In the example below, the userArray is an array of "User" domain objects, with no array key specified. Thus 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. **Translation of select content** The ViewHelper can be given a "translate" argument with configuration on how to translate option labels. The array can have the following keys: - "by" defines if translation by message id or original label is to be used ("id" or "label") - "using" defines if the option tag's "value" or "label" should be used as translation input, defaults to "value" - "locale" defines the locale identifier to use, optional, defaults to current locale - "source" defines the translation source name, optional, defaults to "Main" - "package" defines the package key of the translation source, optional, defaults to current package - "prefix" defines a prefix to use for the message id – only works in combination with "by id" = Examples = (Generates a dropdown box like above, except that "VISA Card" is selected.) (Generates a dropdown box, using ids and first names of the User instances.) (depending on variable "salutations") (Generates a dropdown box and uses the values "payPal" and "visa" to look up translations for those ids in the current package's "Main" XLIFF file.) (Generates a dropdown box and uses the values "shop.paymentOptions.payPal" and "shop.paymentOptions.visa" to look up translations for those ids in the current package's "Main" XLIFF file.)
Inheritance: extends AbstractFormFieldViewHelper
Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$selectedValue mixed
$tagName string
$translator Neos\Flow\I18n\Translator

Public Methods

Method Description
initializeArguments ( ) : void Initialize arguments.
render ( ) : string Render the tag.

Protected Methods

Method Description
getOptionValueScalar ( mixed $valueElement ) : string Get the option value for an object
getOptions ( ) : array Render the option tags.
getSelectedValue ( ) : mixed Retrieves the selected value(s)
getTranslatedLabel ( string $value, string $label ) : string Returns a translated version of the given label
isSelected ( mixed $value ) : boolean Render the option tags.
renderOptionTag ( string $value, string $label ) : string Render one option tag
renderOptionTags ( array $options ) : string Render the option tags.

Method Details

getOptionValueScalar() protected method

Get the option value for an object
protected getOptionValueScalar ( mixed $valueElement ) : string
$valueElement mixed
return string

getOptions() protected method

Render the option tags.
protected getOptions ( ) : array
return array an associative array of options, key will be the value of the option tag

getSelectedValue() protected method

Retrieves the selected value(s)
protected getSelectedValue ( ) : mixed
return mixed value string or an array of strings

getTranslatedLabel() protected method

Returns a translated version of the given label
protected getTranslatedLabel ( string $value, string $label ) : string
$value string option tag value
$label string option tag label
return string

initializeArguments() public method

Initialize arguments.
public initializeArguments ( ) : void
return void

isSelected() protected method

Render the option tags.
protected isSelected ( mixed $value ) : boolean
$value mixed Value to check for
return boolean TRUE if the value should be marked a s selected; FALSE otherwise

render() public method

Render the tag.
public render ( ) : string
return string rendered tag.

renderOptionTag() protected method

Render one option tag
protected renderOptionTag ( string $value, string $label ) : string
$value string value attribute of the option tag (will be escaped)
$label string content of the option tag (will be escaped)
return string the rendered option tag

renderOptionTags() protected method

Render the option tags.
protected renderOptionTags ( array $options ) : string
$options array the options for the form.
return string rendered tags.

Property Details

$selectedValue protected property

protected mixed $selectedValue
return mixed

$tagName protected property

protected string $tagName
return string

$translator protected property

protected Translator,Neos\Flow\I18n $translator
return Neos\Flow\I18n\Translator