Skip to content

Commit 87b16e7

Browse files
committed
[Form] Greatly improved ChoiceListInterface and all of its implementations
Fixes #2869, fixes #3021, fixes #1919, fixes #3153.
1 parent fbbea2f commit 87b16e7

File tree

58 files changed

+3012
-1251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3012
-1251
lines changed

CHANGELOG-2.1.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
166166
* added support for empty form name at root level, this enables rendering forms
167167
without form name prefix in field names
168168

169+
* [BC BREAK] greatly improved `ChoiceListInterface` and all of its
170+
implementations. `EntityChoiceList` was adapted, the methods `getEntities()`,
171+
`getEntitiesByByKeys()`, `getIdentifier()` and `getIdentifierValues()` were
172+
removed/made private. Instead of the first two you can use `getChoices()`
173+
and `getChoicesByValues()`, for the latter two no replacement exists.
174+
`ArrayChoiceList` was replaced by `SimpleChoiceList`.
175+
`PaddedChoiceList`, `MonthChoiceList` and `TimezoneChoiceList` were removed.
176+
Their functionality was merged into `DateType`, `TimeType` and `TimezoneType`.
177+
178+
* [BC BREAK] removed `EntitiesToArrayTransformer` and `EntityToIdTransformer`.
179+
The former has been replaced by `CollectionToArrayTransformer` in combination
180+
with `EntityChoiceList`, the latter is not required in the core anymore.
181+
182+
* [BC BREAK] renamed
183+
184+
* `ArrayToBooleanChoicesTransformer` to `ChoicesToBooleanArrayTransformer`
185+
* `ScalarToBooleanChoicesTransformer` to `ChoiceToBooleanArrayTransformer`
186+
* `ArrayToChoicesTransformer` to `ChoicesToValuesTransformer`
187+
* `ScalarToChoiceTransformer` to `ChoiceToValueTransformer`
188+
189+
to be consistent with the naming in `ChoiceListInterface`.
190+
191+
* [BC BREAK] removed `FormUtil::toArrayKey()` and `FormUtil::toArrayKeys()`.
192+
They were merged into `ChoiceList` and have no public equivalent anymore.
193+
194+
* added `ComplexChoiceList` and `ObjectChoiceList`. Both let you select amongst
195+
objects in a choice field, but feature different constructors.
196+
* choice fields now throw a `FormException` if neither the "choices" nor the
197+
"choice_list" option is set
198+
* the radio field is now a child type of the checkbox field
199+
169200
### HttpFoundation
170201

171202
* added support for streamed responses

UPGRADE-2.1.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,49 @@ UPGRADE FROM 2.0 to 2.1
7676
If you don't want to set the `Valid` constraint, or if there is no reference
7777
from the data of the parent form to the data of the child form, you can
7878
enable BC behaviour by setting the option "cascade_validation" to `true` on
79-
the parent form.
79+
the parent form.
80+
81+
* In the template of the choice type, instead of a single "choices" variable
82+
there are now two variables: "choices" and "choice_labels".
83+
"choices" contains the choices in the values (before they were in the keys)
84+
and "choice_labels" contains the matching labels. Both arrays have
85+
identical keys.
86+
87+
Before:
88+
89+
{% for choice, label in choices %}
90+
<option value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>
91+
{{ label }}
92+
</option>
93+
{% endfor %}
94+
95+
After:
96+
97+
{% for index, choice in choices %}
98+
<option value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>
99+
{{ choice_labels[index] }}
100+
</option>
101+
{% endfor %}
102+
103+
* The strategy for generating the HTML attributes "id" and "name"
104+
of choices in a choice field has changed. Instead of appending the choice
105+
value, a generated integer is now appended by default. Take care if your
106+
Javascript relies on that. If you can guarantee that your choice values only
107+
contain ASCII letters, digits, letters, colons and underscores, you can
108+
restore the old behaviour by setting the option "index_strategy" of the
109+
choice field to `ChoiceList::COPY_CHOICE`.
110+
111+
* The strategy for generating the HTML attributes "value" of choices in a
112+
choice field has changed. Instead of using the choice value, a generated
113+
integer is now stored. Again, take care if your Javascript reads this value.
114+
If your choice field is a non-expanded single-choice field, or if
115+
the choices are guaranteed not to contain the empty string '' (which is the
116+
case when you added it manually or when the field is a single-choice field
117+
and is not required), you can restore the old behaviour by setting the
118+
option "value_strategy" to `ChoiceList::COPY_CHOICE`.
119+
of choices in a choice field has changed. Instead of appending the choice
120+
value, a generated integer is now appended by default. Take care if your
121+
Javascript relies on that. If you can guarantee that your choice values only
122+
contain ASCII letters, digits, letters, colons and underscores, you can
123+
restore the old behaviour by setting the option "index_strategy" of the
124+
choice field to `ChoiceList::COPY_CHOICE`.

0 commit comments

Comments
 (0)