ChoiceListInterface
interface ChoiceListInterface
A list of choices that can be selected in a choice field.
A choice list assigns unique string values to each of a list of choices. These string values are displayed in the "value" attributes in HTML and submitted back to the server.
The acceptable data types for the choices depend on the implementation. Values must always be strings and (within the list) free of duplicates.
Methods
Returns all selectable choices.
Returns the values for the choices.
Returns the values in the structure originally passed to the list.
Returns the original keys of the choices.
Returns the choices corresponding to the given values.
Returns the values corresponding to the given choices.
Details
at line line 33
array
getChoices()
Returns all selectable choices.
at line line 42
string[]
getValues()
Returns the values for the choices.
The values are strings that do not contain duplicates.
at line line 67
string[]
getStructuredValues()
Returns the values in the structure originally passed to the list.
Contrary to {@link getValues()}, the result is indexed by the original keys of the choices. If the original array contained nested arrays, these nested arrays are represented here as well:
$form->add('field', 'choice', array(
'choices' => array(
'Decided' => array('Yes' => true, 'No' => false),
'Undecided' => array('Maybe' => null),
),
));
In this example, the result of this method is:
array(
'Decided' => array('Yes' => '0', 'No' => '1'),
'Undecided' => array('Maybe' => '2'),
)
at line line 89
int[]|string[]
getOriginalKeys()
Returns the original keys of the choices.
The original keys are the keys of the choice array that was passed in the "choice" option of the choice type. Note that this array may contain duplicates if the "choice" option contained choice groups:
$form->add('field', 'choice', array(
'choices' => array(
'Decided' => array(true, false),
'Undecided' => array(null),
),
));
In this example, the original key 0 appears twice, once for true
and
once for null
.
at line line 102
array
getChoicesForValues(array $values)
Returns the choices corresponding to the given values.
The choices are returned with the same keys and in the same order as the corresponding values in the given array.
at line line 115
string[]
getValuesForChoices(array $choices)
Returns the values corresponding to the given choices.
The values are returned with the same keys and in the same order as the corresponding choices in the given array.