8000 [WIP] Remove remaining deprecated interfaces by nicolas-grekas · Pull Request #16097 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Remove remaining deprecated interfaces #16097

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

Closed
wants to merge 1 commit into from
Closed
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
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
25 changes: 0 additions & 25 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['placeholder'] = $options['placeholder'];
}

// BC
$view->vars['empty_value_in_choices'] = $view->vars['placeholder_in_choices'];

if ($options['multiple'] && !$options['expanded']) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
Expand Down Expand Up @@ -249,25 +246,6 @@ public function configureOptions(OptionsResolver $resolver)
return $options['required'] ? null : '';
};

$choiceListNormalizer = function (Options $options) use ($choiceListFactory) {
if (null !== $options['choice_loader']) {
return $choiceListFactory->createListFromLoader(
$options['choice_loader'],
$options['choice_value']
);
}

// 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']);
};

$placeholderNormalizer = function (Options $options, $placeholder) {
if ($options['multiple']) {
// never use an empty value for this case
Expand Down Expand Up @@ -299,7 +277,6 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults(array(
'multiple' => false,
'expanded' => false,
'choice_list' => null, // deprecated
'choices' => array(),
'choices_as_values' => false,
Copy link
Member

Choose a reason for hiding this comment

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

this option should be deprecated saying it has no effect anymore (and the value should be true to reflect the behavior of the code).
The option should be kept though, to allow writing code compatible with 2.8 and 3.0 (passing the value explicitly)

'choice_loader' => null,
Expand All @@ -320,11 +297,9 @@ public function configureOptions(OptionsResolver $resolver)
'choice_translation_domain' => true,
));

$resolver->setNormalizer('choice_list', $choiceListNormalizer);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);

$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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,12 @@ public function finishView(FormView $view, FormInterface $form, array $options)
*/
public function configureOptions(OptionsResolver $resolver)
{
// BC clause for the "intention" option
$csrfTokenId = function (Options $options) {
return $options['intention'];
};

// BC clause for the "csrf_provider" option
$csrfTokenManager = function (Options $options) {
if ($options['csrf_provider'] instanceof CsrfTokenManagerInterface) {
return $options['csrf_provider'];
}

return $options['csrf_provider'] instanceof CsrfTokenManagerAdapter
? $options['csrf_provider']->getTokenManager(false)
: new CsrfProviderAdapter($options['csrf_provider']);
};

$resolver->setDefaults(array(
'csrf_protection' => $this->defaultEnabled,
'csrf_field_name' => $this->defaultFieldName,
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
'csrf_token_manager' => $csrfTokenManager,
'csrf_token_id' => $csrfTokenId,
'csrf_provider' => $this->defaultTokenManager,
'intention' => null,
'csrf_token_manager' => $this->defaultTokenManager,
'csrf_token_id' => null,
));
}

Expand Down
Loading
0