Skip to content

[Form] remove deprecated features #22860

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
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
13 changes: 13 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
CHANGELOG
=========

4.0.0
-----

* using the `choices` option in `CountryType`, `CurrencyType`, `LanguageType`,
`LocaleType`, and `TimezoneType` when the `choice_loader` option is not `null`
is not supported anymore and the configured choices will be ignored
* callable strings that are passed to the options of the `ChoiceType` are
treated as property paths
* the `choices_as_values` option of the `ChoiceType` has been removed
* removed the support for caching loaded choice lists in `LazyChoiceList`,
cache the choice list in the used `ChoiceLoaderInterface` implementation
instead

3.3.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ public function getDecoratedFactory()
*/
public function createListFromChoices($choices, $value = null)
{
if (is_string($value) && !is_callable($value)) {
if (is_string($value)) {
$value = new PropertyPath($value);
} elseif (is_string($value) && is_callable($value)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($value instanceof PropertyPath) {
Expand Down Expand Up @@ -117,10 +115,8 @@ public function createListFromChoices($choices, $value = null)
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
{
if (is_string($value) && !is_callable($value)) {
if (is_string($value)) {
$value = new PropertyPath($value);
} elseif (is_string($value) && is_callable($value)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($value instanceof PropertyPath) {
Expand Down Expand Up @@ -155,10 +151,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
{
$accessor = $this->propertyAccessor;

if (is_string($label) && !is_callable($label)) {
if (is_string($label)) {
$label = new PropertyPath($label);
} elseif (is_string($label) && is_callable($label)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($label instanceof PropertyPath) {
Expand All @@ -167,10 +161,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
};
}

if (is_string($preferredChoices) && !is_callable($preferredChoices)) {
if (is_string($preferredChoices)) {
$preferredChoices = new PropertyPath($preferredChoices);
} elseif (is_string($preferredChoices) && is_callable($preferredChoices)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($preferredChoices instanceof PropertyPath) {
Expand All @@ -184,10 +176,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
};
}

if (is_string($index) && !is_callable($index)) {
if (is_string($index)) {
$index = new PropertyPath($index);
} elseif (is_string($index) && is_callable($index)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($index instanceof PropertyPath) {
Expand All @@ -196,10 +186,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
};
}

if (is_string($groupBy) && !is_callable($groupBy)) {
if (is_string($groupBy)) {
$groupBy = new PropertyPath($groupBy);
} elseif (is_string($groupBy) && is_callable($groupBy)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($groupBy instanceof PropertyPath) {
Expand All @@ -212,10 +200,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
};
}

if (is_string($attr) && !is_callable($attr)) {
if (is_string($attr)) {
$attr = new PropertyPath($attr);
} elseif (is_string($attr) && is_callable($attr)) {
@trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\Closure" instead.', E_USER_DEPRECATED);
}

if ($attr instanceof PropertyPath) {
Expand Down
101 changes: 4 additions & 97 deletions src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ class LazyChoiceList implements ChoiceListInterface
*/
private $value;

/**
* @var ChoiceListInterface|null
*
* @deprecated Since 3.1, to be removed in 4.0. Cache the choice list in the {@link ChoiceLoaderInterface} instead.
*/
private $loadedList;

/**
* @var bool
*
* @deprecated Flag used for BC layer since 3.1. To be removed in 4.0.
*/
private $loaded = false;

/**
* Creates a lazily-loaded list using the given loader.
*
Expand All @@ -79,108 +65,38 @@ public function __construct(ChoiceLoaderInterface $loader, callable $value = nul
*/
public function getChoices()
{
if ($this->loaded) {
// We can safely invoke the {@link ChoiceLoaderInterface} assuming it has the list
// in cache when the lazy list is already loaded
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getChoices();
}

// BC
$this->loadedList = $this->loader->loadChoiceList($this->value);
$this->loaded = true;

return $this->loadedList->getChoices();
// In 4.0 keep the following line only:
// return $this->loader->loadChoiceList($this->value)->getChoices()
return $this->loader->loadChoiceList($this->value)->getChoices();
}

/**
* {@inheritdoc}
*/
public function getValues()
{
if ($this->loaded) {
// Check whether the loader has the same cache
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getValues();
}

// BC
$this->loadedList = $this->loader->loadChoiceList($this->value);
$this->loaded = true;

return $this->loadedList->getValues();
// In 4.0 keep the following line only:
// return $this->loader->loadChoiceList($this->value)->getValues()
return $this->loader->loadChoiceList($this->value)->getValues();
}

/**
* {@inheritdoc}
*/
public function getStructuredValues()
{
if ($this->loaded) {
// Check whether the loader has the same cache
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getStructuredValues();
}

// BC
$this->loadedList = $this->loader->loadChoiceList($this->value);
$this->loaded = true;

return $this->loadedList->getStructuredValues();
// In 4.0 keep the following line only:
// return $this->loader->loadChoiceList($this->value)->getStructuredValues();
return $this->loader->loadChoiceList($this->value)->getStructuredValues();
}

/**
* {@inheritdoc}
*/
public function getOriginalKeys()
{
if ($this->loaded) {
// Check whether the loader has the same cache
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getOriginalKeys();
}

// BC
$this->loadedList = $this->loader->loadChoiceList($this->value);
$this->loaded = true;

return $this->loadedList->getOriginalKeys();
// In 4.0 keep the following line only:
// return $this->loader->loadChoiceList($this->value)->getOriginalKeys();
return $this->loader->loadChoiceList($this->value)->getOriginalKeys();
}

/**
* {@inheritdoc}
*/
public function getChoicesForValues(array $values)
{
if ($this->loaded) {
// Check whether the loader has the same cache
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getChoicesForValues($values);
}

return $this->loader->loadChoicesForValues($values, $this->value);
}

Expand All @@ -189,15 +105,6 @@ public function getChoicesForValues(array $values)
*/
public function getValuesForChoices(array $choices)
{
if ($this->loaded) {
// Check whether the loader has the same cache
if ($this->loadedList !== $this->loader->loadChoiceList($this->value)) {
@trigger_error(sprintf('Caching the choice list in %s is deprecated since 3.1 and will not happen in 4.0. Cache the list in the %s instead.', __CLASS__, ChoiceLoaderInterface::class), E_USER_DEPRECATED);
}

return $this->loadedList->getValuesForChoices($choices);
}

return $this->loader->loadValuesForChoices($choices, $this->value);
}
}
18 changes: 0 additions & 18 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,6 @@ public function configureOptions(OptionsResolver $resolver)
return $options['required'] ? null : '';
};

$choicesAsValuesNormalizer = function (Options $options, $choicesAsValues) {
// Not set by the user
if (null === $choicesAsValues) {
return true;
}

// Set by the user
if (true !== $choicesAsValues) {
throw new \RuntimeException(sprintf('The "choices_as_values" option of the %s should not be used. Remove it and flip the contents of the "choices" option instead.', get_class($this)));
}

@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 true;
};

$placeholderNormalizer = function (Options $options, $placeholder) {
if ($options['multiple']) {
// never use an empty value for this case
Expand Down Expand Up @@ -324,7 +308,6 @@ public function configureOptions(OptionsResolver $resolver)
'multiple' => false,
'expanded' => false,
'choices' => array(),
'choices_as_values' => null, // deprecated since 3.1
'choice_loader' => null,
'choice_label' => null,
'choice_name' => null,
Expand All @@ -345,7 +328,6 @@ public function configureOptions(OptionsResolver $resolver)

$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
$resolver->setNormalizer('choices_as_values', $choicesAsValuesNormalizer);

$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
Expand Down
11 changes: 1 addition & 10 deletions src/Symfony/Component/Form/Extension/Core/Type/CountryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CountryType extends AbstractType implements ChoiceLoaderInterface
Expand All @@ -37,15 +36,7 @@ class CountryType extends AbstractType implements ChoiceLoaderInterface
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);

return null;
}

return $this;
},
'choice_loader' => $this,
'choice_translation_domain' => false,
));
}
Expand Down
11 changes: 1 addition & 10 deletions src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CurrencyType extends AbstractType implements ChoiceLoaderInterface
Expand All @@ -37,15 +36,7 @@ class CurrencyType extends AbstractType implements ChoiceLoaderInterface
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);

return null;
}

return $this;
},
'choice_loader' => $this,
'choice_translation_domain' => false,
));
}
Expand Down
11 changes: 1 addition & 10 deletions src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class LanguageType extends AbstractType implements ChoiceLoaderInterface
Expand All @@ -37,15 +36,7 @@ class LanguageType extends AbstractType implements ChoiceLoaderInterface
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);

return null;
}

return $this;
},
'choice_loader' => $this,
'choice_translation_domain' => false,
));
}
Expand Down
11 changes: 1 addition & 10 deletions src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class LocaleType extends AbstractType implements ChoiceLoaderInterface
Expand All @@ -37,15 +36,7 @@ class LocaleType extends AbstractType implements ChoiceLoaderInterface
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);

return null;
}

return $this;
},
'choice_loader' => $this,
'choice_translation_domain' => false,
));
}
Expand Down
Loading