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
Afficher le fichier Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Свойство Type Description
$selectedValue mixed
$tagName string
$translator Neos\Flow\I18n\Translator

Méthodes publiques

Méthode Description
initializeArguments ( ) : void Initialize arguments.
render ( ) : string Render the tag.

Méthodes protégées

Méthode 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 méthode

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

getOptions() protected méthode

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

getSelectedValue() protected méthode

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

getTranslatedLabel() protected méthode

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
Résultat string

initializeArguments() public méthode

Initialize arguments.
public initializeArguments ( ) : void
Résultat void

isSelected() protected méthode

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

render() public méthode

Render the tag.
public render ( ) : string
Résultat string rendered tag.

renderOptionTag() protected méthode

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)
Résultat string the rendered option tag

renderOptionTags() protected méthode

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

Property Details

$selectedValue protected_oe property

protected mixed $selectedValue
Résultat mixed

$tagName protected_oe property

protected string $tagName
Résultat string

$translator protected_oe property

protected Translator,Neos\Flow\I18n $translator
Résultat Neos\Flow\I18n\Translator