4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Extension\Core\ChoiceList
;
15 * Contains choices that can be selected in a form field.
17 * Each choice has three different properties:
19 * - Choice: The choice that should be returned to the application by the
20 * choice field. Can be any scalar value or an object, but no
22 * - Label: A text representing the choice that is displayed to the user.
23 * - Value: A uniquely identifying value that can contain arbitrary
24 * characters, but no arrays or objects. This value is displayed
25 * in the HTML "value" attribute.
27 * @author Bernhard Schussek <bschussek@gmail.com>
29 interface ChoiceListInterface
32 * Returns the list of choices
34 * @return array The choices with their indices as keys
36 public function getChoices();
39 * Returns the values for the choices
41 * @return array The values with the corresponding choice indices as keys
43 public function getValues();
46 * Returns the choice views of the preferred choices as nested array with
47 * the choice groups as top-level keys.
54 * 10 => ChoiceView object,
55 * 20 => ChoiceView object,
58 * 30 => ChoiceView object,
63 * @return array A nested array containing the views with the corresponding
64 * choice indices as keys on the lowest levels and the choice
65 * group names in the keys of the higher levels
67 public function getPreferredViews();
70 * Returns the choice views of the choices that are not preferred as nested
71 * array with the choice groups as top-level keys.
78 * 10 => ChoiceView object,
79 * 20 => ChoiceView object,
82 * 30 => ChoiceView object,
87 * @return array A nested array containing the views with the corresponding
88 * choice indices as keys on the lowest levels and the choice
89 * group names in the keys of the higher levels
91 * @see getPreferredValues
93 public function getRemainingViews();
96 * Returns the choices corresponding to the given values.
98 * The choices can have any data type.
100 * @param array $values An array of choice values. Not existing values in
101 * this array are ignored
103 * @return array An array of choices with ascending, 0-based numeric keys
105 public function getChoicesForValues(array $values);
108 * Returns the values corresponding to the given choices.
110 * The values must be strings.
112 * @param array $choices An array of choices. Not existing choices in this
115 * @return array An array of choice values with ascending, 0-based numeric
118 public function getValuesForChoices(array $choices);
121 * Returns the indices corresponding to the given choices.
123 * The indices must be positive integers or strings accepted by
124 * {@link FormConfigBuilder::validateName()}.
126 * The index "placeholder" is internally reserved.
128 * @param array $choices An array of choices. Not existing choices in this
131 * @return array An array of indices with ascending, 0-based numeric keys
133 public function getIndicesForChoices(array $choices);
136 * Returns the indices corresponding to the given values.
138 * The indices must be positive integers or strings accepted by
139 * {@link FormConfigBuilder::validateName()}.
141 * The index "placeholder" is internally reserved.
143 * @param array $values An array of choice values. Not existing values in
144 * this array are ignored
146 * @return array An array of indices with ascending, 0-based numeric keys
148 public function getIndicesForValues(array $values);