Symfony2 API
Class

Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList

class SimpleChoiceList extends ChoiceList

A choice list for choices of type string or integer.

Choices and their associated labels can be passed in a single array. Since
choices are passed as array keys, only strings or integer choices are
allowed. Choices may also be given as hierarchy of unlimited depth by
creating nested arrays. The title of the sub-hierarchy can be stored in the
array key pointing to the nested array.

<code>
$choiceList = new SimpleChoiceList(array(
'creditcard' => 'Credit card payment',
'cash' => 'Cash payment',
));
</code>

Methods

__construct(array $choices, array $preferredChoices = array())

Creates a new choice list.

array getChoices()

Returns the list of choices

from ChoiceList
array getValues()

Returns the values for the choices

from ChoiceList
array getPreferredViews()

Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.

from ChoiceList
array getRemainingViews()

Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys.

from ChoiceList
array getChoicesForValues(array $values)

Returns the choices corresponding to the given values.

array getValuesForChoices(array $choices)

Returns the values corresponding to the given choices.

array getIndicesForChoices(array $choices)

Returns the indices corresponding to the given choices.

from ChoiceList
array getIndicesForValues(array $values)

Returns the indices corresponding to the given values.

from ChoiceList

Details

at line 45
public __construct(array $choices, array $preferredChoices = array())

Creates a new choice list.

Parameters

array $choices The array of choices with the choices as keys and the labels as values. Choices may also be given as hierarchy of unlimited depth by creating nested arrays. The title of the sub-hierarchy is stored in the array key pointing to the nested array.
array $preferredChoices A flat array of choices that should be presented to the user with priority.

Exceptions

UnexpectedTypeException If the choices are not an array or \Traversable.

in ChoiceList at line 121
public array getChoices()

Returns the list of choices

Return Value

array The choices with their indices as keys.

in ChoiceList at line 129
public array getValues()

Returns the values for the choices

Return Value

array The values with the corresponding choice indices as keys.

in ChoiceList at line 137
public array getPreferredViews()

Returns the choice views of the preferred choices as nested array with the choice groups as top-level keys.

Example:

<source>
array(
'Group 1' => array(
10 => ChoiceView object,
20 => ChoiceView object,
),
'Group 2' => array(
30 => ChoiceView object,
),
)
</source>

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels.

in ChoiceList at line 145
public array getRemainingViews()

Returns the choice views of the choices that are not preferred as nested array with the choice groups as top-level keys.

Example:

<source>
array(
'Group 1' => array(
10 => ChoiceView object,
20 => ChoiceView object,
),
'Group 2' => array(
30 => ChoiceView object,
),
)
</source>

Return Value

array A nested array containing the views with the corresponding choice indices as keys on the lowest levels and the choice group names in the keys of the higher levels.

at line 54
public array getChoicesForValues(array $values)

Returns the choices corresponding to the given values.

Parameters

array $values An array of choice values. Not existing values in this array are ignored.

Return Value

array An array of choices with ascending, 0-based numeric keys

at line 66
public array getValuesForChoices(array $choices)

Returns the values corresponding to the given choices.

Parameters

array $choices An array of choices. Not existing choices in this array are ignored.

Return Value

array An array of choice values with ascending, 0-based numeric keys

in ChoiceList at line 201
public array getIndicesForChoices(array $choices)

Returns the indices corresponding to the given choices.

Parameters

array $choices An array of choices. Not existing choices in this array are ignored.

Return Value

array An array of indices with ascending, 0-based numeric keys

in ChoiceList at line 225
public array getIndicesForValues(array $values)

Returns the indices corresponding to the given values.

Parameters

array $values An array of choice values. Not existing values in this array are ignored.

Return Value

array An array of indices with ascending, 0-based numeric keys