8000 [Form] Remove choices_as_values option on ChoiceType by nicolas-grekas · Pull Request #16715 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Remove choices_as_values option on ChoiceType #16715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ public function configureOptions(OptionsResolver $resolver)
'em' => null,
'query_builder' => null,
'choices' => null,
'choices_as_values' => true,
'choice_loader' => $choiceLoader,
'choice_label' => array(__CLASS__, 'createChoiceLabel'),
'choice_name' => $choiceName,
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require-dev": {
"symfony/stopwatch": "~2.8|~3.0",
"symfony/dependency-injection": "~2.8|~3.0",
"symfony/form": "~2.8|~3.0",
"symfony/form": "~3.0,>3.0-BETA1",
"symfony/http-kernel": "~2.8|~3.0",
"symfony/property-access": "~2.8|~3.0",
"symfony/property-info": "~2.8|3.0",
Expand Down
190 changes: 0 additions & 190 deletions src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,6 @@ public function createListFromChoices($choices, $value = null)
return $this->lists[$hash];
}

/**
* {@inheritdoc}
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
* removed in Symfony 3.0.
*/
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
{
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);
}

// The value is not validated on purpose. The decorated factory may
// decide which values to accept and which not.

// We ignore the choice groups for caching. If two choice lists are
// requested with the same choices, but a different grouping, the same
// choice list is returned.
self::flatten($choices, $flatChoices);

$hash = self::generateHash(array($flatChoices, $value), 'fromFlippedChoices');

if (!isset($this->lists[$hash])) {
$this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
}

return $this->lists[$hash];
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@ interface ChoiceListFactoryInterface
*/
public function createListFromChoices($choices, $value = null);

/**
* Creates a choice list for the given choices.
*
* The choices should be passed in the keys of the choices array. Since the
* choices array will be flipped, the entries of the array must be strings
* or integers.
*
* Optionally, a callable can be passed for generating the choice values.
* The callable receives the choice as first and the array key as the second
* argument.
*
* @param array|\Traversable $choices The choices
* @param null|callable $value The callable generating the choice
* values
*
* @return ChoiceListInterface The choice list
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
* removed in Symfony 3.0.
*/
public function createListFromFlippedChoices($choices, $value = null);

/**
* Creates a choice list that is loaded with the given loader.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Form\ChoiceList\Factory;

use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
Expand All @@ -35,21 +34,6 @@ public function createListFromChoices($choices, $value = null)
return new ArrayChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
* removed in Symfony 3.0.
*/
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
{
if ($triggerDeprecationNotice) {
@trigger_error('The '.__METHOD__.' is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
}

return new ArrayKeyChoiceList($choices, $value);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,6 @@ public function createListFromChoices($choices, $value = null)
return $this->decoratedFactory->createListFromChoices($choices, $value);
}

/**
* {@inheritdoc}
*
* @param array|\Traversable $choices The choices
* @param null|callable|string|PropertyPath $value The callable or path for
* generating the choice values
*
* @return ChoiceListInterface The choice list
*
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
* removed in Symfony 3.0.
*/
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
{
// Property paths are not supported here, because array keys can never
// be objects
return $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
}

/**
* {@inheritdoc}
*
Expand Down
18 changes: 8 additions & 10 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,19 @@ public function configureOptions(OptionsResolver $resolver)
// Harden against NULL values (like in EntityType and ModelType)
$choices = null !== $options['choices'] ? $options['choices'] : array();

// BC when choices are in the keys, not in the values
if (!$options['choices_as_values']) {
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value'], false);
}

return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
};

$choicesAsValuesNormalizer = function (Options $options, $choicesAsValues) {
if (true !== $choicesAsValues) {
@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);
if (null !== $choicesAsValues) {
if (true !== $choicesAsValues) {
throw new \RuntimeException('The "choices_as_values" option should not be used. Remove it and flip the contents of the "choices" option instead.');
}
// To be uncommented in 3.1
//@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);
}

return $choicesAsValues;
return true;
};

$placeholderNormalizer = function (Options $options, $placeholder) {
Expand Down Expand Up @@ -309,7 +308,7 @@ public function configureOptions(OptionsResolver $resolver)
'expanded' => false,
'choice_list' => null, // deprecated
'choices' => array(),
'choices_as_values' => false,
'choices_as_values' => null, // to be deprecated in 3.1
'choice_loader' => null,
'choice_label' => null,
'choice_name' => null,
Expand All @@ -336,7 +33 F438 5,6 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface'));
$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
$resolver->setAllowedTypes('choices_as_values', 'bool');
$resolver->setAllowedTypes('choice_loader', array('null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface'));
$resolver->setAllowedTypes('choice_label', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to remove this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the default is null now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use array('null', 'bool') then (well okay, technically it does not make much of a difference as the user would get an error anyway)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not tech diff as you said, and since this line is going to be removed anyway in 3.1, there is no need to keep it

$resolver->setAllowedTypes('choice_name', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => array_flip(Intl::getRegionBundle()->getCountryNames()),
'choices_as_values' => true,
'choice_translation_domain' => false,
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => array_flip(Intl::getCurrencyBundle()->getCurrencyNames()),
'choices_as_values' => true,
'choice_translation_domain' => false,
));
}
Expand Down
Loading
0