Skip to content

Commit ed0e26a

Browse files
[Form] Remove choices_as_values option on ChoiceType
1 parent ba3afdb commit ed0e26a

20 files changed

+9
-755
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,>3.0-BETA1",
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/ChoiceList/ArrayKeyChoiceList.php

Lines changed: 0 additions & 190 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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,19 @@ 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+
if (true !== $choicesAsValues) {
269+
throw new \RuntimeException('The "choices_as_values" option should not be used. Remove it and flip the contents of the "choices" option instead.');
270+
}
271+
// To be uncommented in 3.1
272+
//@trigger_error('The "choices_as_values" option is deprecated since version 3.1 and will be removed in 4.0. You should not use it anymore.', E_USER_DEPRECATED);
274273
}
275274

276-
return $choicesAsValues;
275+
return true;
277276
};
278277

279278
$placeholderNormalizer = function (Options $options, $placeholder) {
@@ -309,7 +308,7 @@ public function configureOptions(OptionsResolver $resolver)
309308
'expanded' => false,
310309
'choice_list' => null, // deprecated
311310
'choices' => array(),
312-
'choices_as_values' => false,
311+
'choices_as_values' => null, // to be deprecated in 3.1
313312
'choice_loader' => null,
314313
'choice_label' => null,
315314
'choice_name' => null,
@@ -336,7 +335,6 @@ public function configureOptions(OptionsResolver $resolver)
336335
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface'));
337336
$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
338337
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
339-
$resolver->setAllowedTypes('choices_as_values', 'bool');
340338
$resolver->setAllowedTypes('choice_loader', array('null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface'));
341339
$resolver->setAllowedTypes('choice_label', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
342340
$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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy