Skip to content

Commit bbe40d5

Browse files
committed
Remove deprecated implementation of ChoiceLoaderInterface in intl forms
1 parent 9cc2a4e commit bbe40d5

File tree

8 files changed

+12
-340
lines changed

8 files changed

+12
-340
lines changed

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

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15-
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
16-
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1715
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
1816
use Symfony\Component\Intl\Countries;
1917
use Symfony\Component\OptionsResolver\Options;
2018
use Symfony\Component\OptionsResolver\OptionsResolver;
2119

22-
class CountryType extends AbstractType implements ChoiceLoaderInterface
20+
class CountryType extends AbstractType
2321
{
24-
/**
25-
* Country loaded choice list.
26-
*
27-
* The choices are lazy loaded and generated from the Intl component.
28-
*
29-
* {@link \Symfony\Component\Intl\Intl::getRegionBundle()}.
30-
*
31-
* @var ArrayChoiceList
32-
*
33-
* @deprecated since Symfony 4.1
34-
*/
35-
private $choiceList;
36-
3722
/**
3823
* {@inheritdoc}
3924
*/
4025
public function configureOptions(OptionsResolver $resolver)
4126
{
4227
$resolver->setDefaults([
43-
'choice_loader' => function (Options $options) {
28+
'choice_loader' => static function (Options $options) {
4429
$choiceTranslationLocale = $options['choice_translation_locale'];
4530

46-
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
31+
return new IntlCallbackChoiceLoader(static function () use ($choiceTranslationLocale) {
4732
return array_flip(Countries::getNames($choiceTranslationLocale));
4833
});
4934
},
@@ -69,61 +54,4 @@ public function getBlockPrefix()
6954
{
7055
return 'country';
7156
}
72-
73-
/**
74-
* {@inheritdoc}
75-
*
76-
* @deprecated since Symfony 4.1
77-
*/
78-
public function loadChoiceList($value = null)
79-
{
80-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
81-
82-
if (null !== $this->choiceList) {
83-
return $this->choiceList;
84-
}
85-
86-
return $this->choiceList = new ArrayChoiceList(array_flip(Countries::getNames()), $value);
87-
}
88-
89-
/**
90-
* {@inheritdoc}
91-
*
92-
* @deprecated since Symfony 4.1
93-
*/
94-
public function loadChoicesForValues(array $values, $value = null)
95-
{
96-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
97-
98-
// Optimize
99-
$values = array_filter($values);
100-
if (empty($values)) {
101-
return [];
102-
}
103-
104-
return $this->loadChoiceList($value)->getChoicesForValues($values);
105-
}
106-
107-
/**
108-
* {@inheritdoc}
109-
*
110-
* @deprecated since Symfony 4.1
111-
*/
112-
public function loadValuesForChoices(array $choices, $value = null)
113-
{
114-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
115-
116-
// Optimize
117-
$choices = array_filter($choices);
118-
if (empty($choices)) {
119-
return [];
120-
}
121-
122-
// If no callable is set, choices are the same as values
123-
if (null === $value) {
124-
return $choices;
125-
}
126-
127-
return $this->loadChoiceList($value)->getValuesForChoices($choices);
128-
}
12957
}

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

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15-
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
16-
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1715
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
1816
use Symfony\Component\Intl\Currencies;
1917
use Symfony\Component\OptionsResolver\Options;
2018
use Symfony\Component\OptionsResolver\OptionsResolver;
2119

22-
class CurrencyType extends AbstractType implements ChoiceLoaderInterface
20+
class CurrencyType extends AbstractType
2321
{
24-
/**
25-
* Currency loaded choice list.
26-
*
27-
* The choices are lazy loaded and generated from the Intl component.
28-
*
29-
* {@link \Symfony\Component\Intl\Intl::getCurrencyBundle()}.
30-
*
31-
* @var ArrayChoiceList
32-
*
33-
* @deprecated since Symfony 4.1
34-
*/
35-
private $choiceList;
36-
3722
/**
3823
* {@inheritdoc}
3924
*/
4025
public function configureOptions(OptionsResolver $resolver)
4126
{
4227
$resolver->setDefaults([
43-
'choice_loader' => function (Options $options) {
28+
'choice_loader' => static function (Options $options) {
4429
$choiceTranslationLocale = $options['choice_translation_locale'];
4530

46-
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
31+
return new IntlCallbackChoiceLoader(static function () use ($choiceTranslationLocale) {
4732
return array_flip(Currencies::getNames($choiceTranslationLocale));
4833
});
4934
},
@@ -69,61 +54,4 @@ public function getBlockPrefix()
6954
{
7055
return 'currency';
7156
}
72-
73-
/**
74-
* {@inheritdoc}
75-
*
76-
* @deprecated since Symfony 4.1
77-
*/
78-
public function loadChoiceList($value = null)
79-
{
80-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
81-
82-
if (null !== $this->choiceList) {
83-
return $this->choiceList;
84-
}
85-
86-
return $this->choiceList = new ArrayChoiceList(array_flip(Currencies::getNames()), $value);
87-
}
88-
89-
/**
90-
* {@inheritdoc}
91-
*
92-
* @deprecated since Symfony 4.1
93-
*/
94-
public function loadChoicesForValues(array $values, $value = null)
95-
{
96-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
97-
98-
// Optimize
99-
$values = array_filter($values);
100-
if (empty($values)) {
101-
return [];
102-
}
103-
104-
return $this->loadChoiceList($value)->getChoicesForValues($values);
105-
}
106-
107-
/**
108-
* {@inheritdoc}
109-
*
110-
* @deprecated since Symfony 4.1
111-
*/
112-
public function loadValuesForChoices(array $choices, $value = null)
113-
{
114-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
115-
116-
// Optimize
117-
$choices = array_filter($choices);
118-
if (empty($choices)) {
119-
return [];
120-
}
121-
122-
// If no callable is set, choices are the same as values
123-
if (null === $value) {
124-
return $choices;
125-
}
126-
127-
return $this->loadChoiceList($value)->getValuesForChoices($choices);
128-
}
12957
}

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

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15-
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
16-
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1715
use Symfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
1816
use Symfony\Component\Intl\Languages;
1917
use Symfony\Component\OptionsResolver\Options;
2018
use Symfony\Component\OptionsResolver\OptionsResolver;
2119

22-
class LanguageType extends AbstractType implements ChoiceLoaderInterface
20+
class LanguageType extends AbstractType
2321
{
24-
/**
25-
* Language loaded choice list.
26-
*
27-
* The choices are lazy loaded and generated from the Intl component.
28-
*
29-
* {@link \Symfony\Component\Intl\Intl::getLanguageBundle()}.
30-
*
31-
* @var ArrayChoiceList
32-
*
33-
* @deprecated since Symfony 4.1
34-
*/
35-
private $choiceList;
36-
3722
/**
3823
* {@inheritdoc}
3924
*/
4025
public function configureOptions(OptionsResolver $resolver)
4126
{
4227
$resolver->setDefaults([
43-
'choice_loader' => function (Options $options) {
28+
'choice_loader' => static function (Options $options) {
4429
$choiceTranslationLocale = $options['choice_translation_locale'];
4530

46-
return new IntlCallbackChoiceLoader(function () use ($choiceTranslationLocale) {
31+
return new IntlCallbackChoiceLoader(static function () use ($choiceTranslationLocale) {
4732
return array_flip(Languages::getNames($choiceTranslationLocale));
4833
});
4934
},
@@ -69,61 +54,4 @@ public function getBlockPrefix()
6954
{
7055
return 'language';
7156
}
72-
73-
/**
74-
* {@inheritdoc}
75-
*
76-
* @deprecated since Symfony 4.1
77-
*/
78-
public function loadChoiceList($value = null)
79-
{
80-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
81-
82-
if (null !== $this->choiceList) {
83-
return $this->choiceList;
84-
}
85-
86-
return $this->choiceList = new ArrayChoiceList(array_flip(Languages::getNames()), $value);
87-
}
88-
89-
/**
90-
* {@inheritdoc}
91-
*
92-
* @deprecated since Symfony 4.1
93-
*/
94-
public function loadChoicesForValues(array $values, $value = null)
95-
{
96-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
97-
98-
// Optimize
99-
$values = array_filter($values);
100-
if (empty($values)) {
101-
return [];
102-
}
103-
104-
return $this->loadChoiceList($value)->getChoicesForValues($values);
105-
}
106-
107-
/**
108-
* {@inheritdoc}
109-
*
110-
* @deprecated since Symfony 4.1
111-
*/
112-
public function loadValuesForChoices(array $choices, $value = null)
113-
{
114-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use the "choice_loader" option instead.', __METHOD__), E_USER_DEPRECATED);
115-
116-
// Optimize
117-
$choices = array_filter($choices);
118-
if (empty($choices)) {
119-
return [];
120-
}
121-
122-
// If no callable is set, choices are the same as values
123-
if (null === $value) {
124-
return $choices;
125-
}
126-
127-
return $this->loadChoiceList($value)->getValuesForChoices($choices);
128-
}
12957
}

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