8000 [Form] Remove choices_as_values option on ChoiceType · symfony/symfony@32b4b19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32b4b19

Browse files
[Form] Remove choices_as_values option on ChoiceType
1 parent 743e670 commit 32b4b19

21 files changed

+7
-754
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ public function configureOptions(OptionsResolver $resolver)
259259
'em' => null,
260260
'query_builder' => null,
261261
'choices' => null,
262-
'choices_as_values' => true,
263262
'choice_loader' => $choiceLoader,
264263
'choice_label' => array(__CLASS__, 'createChoiceLabel'),
265264
'choice_name' => $choiceName,

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"symfony/stopwatch": "~2.8|~3.0",
2424
"symfony/dependency-injection": "~2.8|~3.0",
25-
"symfony/form": "~2.8|~3.0",
25+
"symfony/form": "~3.0",
2626
"symfony/http-kernel": "~2.8|~3.0",
2727
"symfony/property-access": "~2.8|~3.0",
2828
"symfony/property-info": "~2.8|3.0",

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* removed `AbstractTypeExtension::setDefaultOptions()` method
1111
* added `FormTypeInterface::configureOptions()` method
1212
* added `FormTypeExtensionInterface::configureOptions()` method
13+
* deprecated the "choices_as_values" option of ChoiceType
1314

1415
2.8.0
1516
-----

src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php

Lines changed: 0 additions & 188 deletions
This file was deleted.

src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,35 +135,6 @@ public function createListFromChoices($choices, $value = null)
135135
return $this->lists[$hash];
136136
}
137137

138-
/**
139-
* {@inheritdoc}
140-
*
141-
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
142-
* removed in Symfony 3.0.
143-
*/
144-
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
145-
{
146-
if ($choices instanceof \Traversable) {
147-
$choices = iterator_to_array($choices);
148-
}
149-
150-
// The value is not validated on purpose. The decorated factory may
151-
// decide which values to accept and which not.
152-
153-
// We ignore the choice groups for caching. If two choice lists are
154-
// requested with the same choices, but a different grouping, the same
155-
// choice list is returned.
156-
self::flatten($choices, $flatChoices);
157-
158-
$hash = self::generateHash(array($flatChoices, $value), 'fromFlippedChoices');
159-
160-
if (!isset($this->lists[$hash])) {
161-
$this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
162-
}
163-
164-
return $this->lists[$hash];
165-
}
166-
167138
/**
168139
* {@inheritdoc}
169140
*/

src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,6 @@ interface ChoiceListFactoryInterface
3939
*/
4040
public function createListFromChoices($choices, $value = null);
4141

42-
/**
43-
* Creates a choice list for the given choices.
44-
*
45-
* The choices should be passed in the keys of the choices array. Since the
46-
* choices array will be flipped, the entries of the array must be strings
47-
* or integers.
48-
*
49-
* Optionally, a callable can be passed for generating the choice values.
50-
* The callable receives the choice as first and the array key as the second
51-
* argument.
52-
*
53-
* @param array|\Traversable $choices The choices
54-
* @param null|callable $value The callable generating the choice
55-
* values
56-
*
57-
* @return ChoiceListInterface The choice list
58-
*
59-
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
60-
* removed in Symfony 3.0.
61-
*/
62-
public function createListFromFlippedChoices($choices, $value = null);
63-
6442
/**
6543
* Creates a choice list that is loaded with the given loader.
6644
*

src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Form\ChoiceList\Factory;
1313

14-
use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList;
1514
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
1615
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1716
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
@@ -35,21 +34,6 @@ public function createListFromChoices($choices, $value = null)
3534
return new ArrayChoiceList($choices, $value);
3635
}
3736

38-
/**
39-
* {@inheritdoc}
40-
*
41-
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
42-
* removed in Symfony 3.0.
43-
*/
44-
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
45-
{
46-
if ($triggerDeprecationNotice) {
47-
@trigger_error('The '.__METHOD__.' is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
48-
}
49-
50-
return new ArrayKeyChoiceList($choices, $value);
51-
}
52-
5337
/**
5438
* {@inheritdoc}
5539
*/

src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,6 @@ public function createListFromChoices($choices, $value = null)
104104
return $this->decoratedFactory->createListFromChoices($choices, $value);
105105
}
106106

107-
/**
108-
* {@inheritdoc}
109-
*
110-
* @param array|\Traversable $choices The choices
111-
* @param null|callable|string|PropertyPath $value The callable or path for
112-
* generating the choice values
113-
*
114-
* @return ChoiceListInterface The choice list
115-
*
116-
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
117-
* removed in Symfony 3.0.
118-
*/
119-
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
120-
{
121-
// Property paths are not supported here, because array keys can never
122-
// be objects
123-
return $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
124-
}
125-
126107
/**
127108
* {@inheritdoc}
128109
*

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,15 @@ public function configureOptions(OptionsResolver $resolver)
260260
// Harden against NULL values (like in EntityType and ModelType)
261261
$choices = null !== $options['choices'] ? $options['choices'] : array();
262262

263-
// BC when choices are in the keys, not in the values
264-
if (!$options['choices_as_values']) {
265-
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value'], false);
266-
}
267-
268263
return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
269264
};
270265

271266
$choicesAsValuesNormalizer = function (Options $options, $choicesAsValues) {
272-
if (true !== $choicesAsValues) {
273-
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED);
267+
if (null !== $choicesAsValues) {
268+
@trigger_error('The "choices_as_values" option is ignored since version 3.0 and will be removed in 4.0.', E_USER_DEPRECATED);
274269
}
275270

276-
return $choicesAsValues;
271+
return true;
277272
};
278273

279274
$placeholderNormalizer = function (Options $options, $placeholder) {
@@ -309,7 +304,7 @@ public function configureOptions(OptionsResolver $resolver)
309304
'expanded' => false,
310305
'choice_list' => null, // deprecated
311306
'choices' => array(),
312-
'choices_as_values' => false,
307+
'choices_as_values' => null, // deprecated in 3.0
313308
'choice_loader' => null,
314309
'choice_label' => null,
315310
'choice_name' => null,
@@ -336,7 +331,6 @@ public function configureOptions(OptionsResolver $resolver)
336331
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface'));
337332
$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
338333
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
339-
$resolver->setAllowedTypes('choices_as_values', 'bool');
340334
$resolver->setAllowedTypes('choice_loader', array('null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface'));
341335
$resolver->setAllowedTypes('choice_label', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
342336
$resolver->setAllowedTypes('choice_name', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));

src/Symfony/Component/Form/Extension/Core/Type/CountryType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function configureOptions(OptionsResolver $resolver)
2424
{
2525
$resolver->setDefaults(array(
2626
'choices' => array_flip(Intl::getRegionBundle()->getCountryNames()),
27-
'choices_as_values' => true,
2827
'choice_translation_domain' => false,
2928
));
3029
}

src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function configureOptions(OptionsResolver $resolver)
2424
{
2525
$resolver->setDefaults(array(
2626
'choices' => array_flip(Intl::getCurrencyBundle()->getCurrencyNames()),
27-
'choices_as_values' => true,
2827
'choice_translation_domain' => false,
2928
));
3029
}

0 commit comments

Comments
 (0)
0