Permalink
Browse files

[Form] Greatly improved ChoiceListInterface and all of its implementa…

…tions

Fixes #2869, fixes #3021, fixes #1919, fixes #3153.
  • Loading branch information...
1 parent fbbea2f commit 87b16e7015c02e794c33dbfc05812cf070b4ac68 @webmozart webmozart committed Jan 16, 2012
Showing with 3,012 additions and 1,251 deletions.
  1. +31 −0 CHANGELOG-2.1.md
  2. +46 −1 UPGRADE-2.1.md
  3. +255 −149 src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
  4. +11 −1 src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php
  5. +16 −0 src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php
  6. +63 −0 src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php
  7. +0 −98 src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntitiesToArrayTransformer.php
  8. +0 −83 src/Symfony/Bridge/Doctrine/Form/DataTransformer/EntityToIdTransformer.php
  9. +3 −5 src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
  10. +6 −6 src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
  11. +6 −6 src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php
  12. +16 −0 src/Symfony/Component/Form/Exception/StringCastException.php
  13. +0 −69 src/Symfony/Component/Form/Extension/Core/ChoiceList/ArrayChoiceList.php
  14. +649 −0 src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php
  15. +116 −2 src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php
  16. +44 −0 src/Symfony/Component/Form/Extension/Core/ChoiceList/ComplexChoiceList.php
  17. +0 −58 src/Symfony/Component/Form/Extension/Core/ChoiceList/MonthChoiceList.php
  18. +201 −0 src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php
  19. +0 −59 src/Symfony/Component/Form/Extension/Core/ChoiceList/PaddedChoiceList.php
  20. +133 −0 src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php
  21. +0 −63 src/Symfony/Component/Form/Extension/Core/ChoiceList/TimezoneChoiceList.php
  22. +26 −16 ...ore/DataTransformer/{ScalarToBooleanChoicesTransformer.php → ChoiceToBooleanArrayTransformer.php}
  23. +63 −0 src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php
  24. +32 −12 ...ore/DataTransformer/{ArrayToBooleanChoicesTransformer.php → ChoicesToBooleanArrayTransformer.php}
  25. +27 −3 ...m/Extension/Core/DataTransformer/{ArrayToChoicesTransformer.php → ChoicesToValuesTransformer.php}
  26. +0 −37 src/Symfony/Component/Form/Extension/Core/DataTransformer/ScalarToChoiceTransformer.php
  27. +16 −2 src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php
  28. +38 −35 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
  29. +3 −0 src/Symfony/Component/Form/Extension/Core/Type/CountryType.php
  30. +48 −11 src/Symfony/Component/Form/Extension/Core/Type/DateType.php
  31. +2 −0 src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php
  32. +2 −0 src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php
  33. +1 −27 src/Symfony/Component/Form/Extension/Core/Type/RadioType.php
  34. +25 −10 src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
  35. +51 −3 src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php
  36. +0 −18 src/Symfony/Component/Form/Util/FormUtil.php
  37. +14 −12 tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php
  38. +35 −30 tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php
  39. +58 −60 tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php
  40. +0 −53 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ArrayChoiceListTest.php
  41. +143 −0 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ComplexChoiceListTest.php
  42. +0 −95 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/MonthChoiceListTest.php
  43. +249 −0 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ObjectChoiceListTest.php
  44. +0 −54 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/PaddedChoiceListTest.php
  45. +222 −0 tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/SimpleChoiceListTest.php
  46. +11 −16 ...nsion/Core/DataTransformer/{ScalarToChoiceTransformerTest.php → ChoiceToValueTransformerTest.php}
  47. +12 −8 ...ion/Core/DataTransformer/{ArrayToChoicesTransformerTest.php → ChoicesToValuesTransformerTest.php}
  48. +23 −8 tests/Symfony/Tests/Component/Form/Extension/Core/EventListener/FixRadioInputListenerTest.php
  49. +213 −35 tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php
  50. +12 −11 tests/Symfony/Tests/Component/Form/Extension/Core/Type/CountryTypeTest.php
  51. +3 −0 tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTimeTypeTest.php
  52. +51 −3 tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
  53. +12 −11 tests/Symfony/Tests/Component/Form/Extension/Core/Type/LanguageTypeTest.php
  54. +7 −6 tests/Symfony/Tests/Component/Form/Extension/Core/Type/LocaleTypeTest.php
  55. +0 −26 tests/Symfony/Tests/Component/Form/Extension/Core/Type/RadioTypeTest.php
  56. +3 −3 tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php
  57. +5 −4 tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimezoneTypeTest.php
  58. +9 −42 tests/Symfony/Tests/Component/Form/Util/FormUtilTest.php
View
@@ -166,6 +166,37 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
* added support for empty form name at root level, this enables rendering forms
without form name prefix in field names
+ * [BC BREAK] greatly improved `ChoiceListInterface` and all of its
+ implementations. `EntityChoiceList` was adapted, the methods `getEntities()`,
+ `getEntitiesByByKeys()`, `getIdentifier()` and `getIdentifierValues()` were
+ removed/made private. Instead of the first two you can use `getChoices()`
+ and `getChoicesByValues()`, for the latter two no replacement exists.
+ `ArrayChoiceList` was replaced by `SimpleChoiceList`.
@willdurand
willdurand Feb 1, 2012 Contributor

The Propel1 bridge is now broken.. Please, don't forget it as you did the job for the Doctrine bridge :)

@webmozart
webmozart Feb 2, 2012 Member

Why is there no failing test case for this? Can you please open a ticket?

+ `PaddedChoiceList`, `MonthChoiceList` and `TimezoneChoiceList` were removed.
+ Their functionality was merged into `DateType`, `TimeType` and `TimezoneType`.
+
+ * [BC BREAK] removed `EntitiesToArrayTransformer` and `EntityToIdTransformer`.
+ The former has been replaced by `CollectionToArrayTransformer` in combination
+ with `EntityChoiceList`, the latter is not required in the core anymore.
+
+ * [BC BREAK] renamed
+
+ * `ArrayToBooleanChoicesTransformer` to `ChoicesToBooleanArrayTransformer`
+ * `ScalarToBooleanChoicesTransformer` to `ChoiceToBooleanArrayTransformer`
+ * `ArrayToChoicesTransformer` to `ChoicesToValuesTransformer`
+ * `ScalarToChoiceTransformer` to `ChoiceToValueTransformer`
+
+ to be consistent with the naming in `ChoiceListInterface`.
+
+ * [BC BREAK] removed `FormUtil::toArrayKey()` and `FormUtil::toArrayKeys()`.
+ They were merged into `ChoiceList` and have no public equivalent anymore.
+
+ * added `ComplexChoiceList` and `ObjectChoiceList`. Both let you select amongst
+ objects in a choice field, but feature different constructors.
+ * choice fields now throw a `FormException` if neither the "choices" nor the
+ "choice_list" option is set
+ * the radio field is now a child type of the checkbox field
+
### HttpFoundation
* added support for streamed responses
View
@@ -76,4 +76,49 @@ UPGRADE FROM 2.0 to 2.1
If you don't want to set the `Valid` constraint, or if there is no reference
from the data of the parent form to the data of the child form, you can
enable BC behaviour by setting the option "cascade_validation" to `true` on
- the parent form.
+ the parent form.
+
+* In the template of the choice type, instead of a single "choices" variable
+ there are now two variables: "choices" and "choice_labels".
+ "choices" contains the choices in the values (before they were in the keys)
+ and "choice_labels" contains the matching labels. Both arrays have
+ identical keys.
+
+ Before:
+
+ {% for choice, label in choices %}
+ <option value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>
+ {{ label }}
+ </option>
+ {% endfor %}
+
+ After:
+
+ {% for index, choice in choices %}
+ <option value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>
+ {{ choice_labels[index] }}
+ </option>
+ {% endfor %}
+
+* The strategy for generating the HTML attributes "id" and "name"
+ of choices in a choice field has changed. Instead of appending the choice
+ value, a generated integer is now appended by default. Take care if your
+ Javascript relies on that. If you can guarantee that your choice values only
+ contain ASCII letters, digits, letters, colons and underscores, you can
+ restore the old behaviour by setting the option "index_strategy" of the
+ choice field to `ChoiceList::COPY_CHOICE`.
+
+* The strategy for generating the HTML attributes "value" of choices in a
+ choice field has changed. Instead of using the choice value, a generated
+ integer is now stored. Again, take care if your Javascript reads this value.
+ If your choice field is a non-expanded single-choice field, or if
+ the choices are guaranteed not to contain the empty string '' (which is the
+ case when you added it manually or when the field is a single-choice field
+ and is not required), you can restore the old behaviour by setting the
+ option "value_strategy" to `ChoiceList::COPY_CHOICE`.
+ of choices in a choice field has changed. Instead of appending the choice
+ value, a generated integer is now appended by default. Take care if your
+ Javascript relies on that. If you can guarantee that your choice values only
+ contain ASCII letters, digits, letters, colons and underscores, you can
+ restore the old behaviour by setting the option "index_strategy" of the
+ choice field to `ChoiceList::COPY_CHOICE`.
Oops, something went wrong.

0 comments on commit 87b16e7

Please sign in to comment.