Skip to content

Commit d5f0a26

Browse files
minor #31665 [Form] Remove deprecated implementation of ChoiceLoaderInterface in intl forms (yceruto)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Form] Remove deprecated implementation of ChoiceLoaderInterface in intl forms | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See previous PR #26825 (4.1) Commits ------- b22cbf4 Remove deprecated implementation of ChoiceLoaderInterface in intl forms
2 parents 42975ba + b22cbf4 commit d5f0a26

File tree

8 files changed

+4
-336
lines changed

8 files changed

+4
-336
lines changed

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

+1-73
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
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
*/
@@ -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

+1-73
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
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
*/
@@ -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

+1-73
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
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
*/
@@ -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
}

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

+1-73
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
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\Locales;
1917
use Symfony\Component\OptionsResolver\Options;
2018
use Symfony\Component\OptionsResolver\OptionsResolver;
2119

22-
class LocaleType extends AbstractType implements ChoiceLoaderInterface
20+
class LocaleType extends AbstractType
2321
{
24-
/**
25-
* Locale loaded choice list.
26-
*
27-
* The choices are lazy loaded and generated from the Intl component.
28-
*
29-
* {@link \Symfony\Component\Intl\Intl::getLocaleBundle()}.
30-
*
31-
* @var ArrayChoiceList
32-
*
33-
* @deprecated since Symfony 4.1
34-
*/
35-
private $choiceList;
36-
3722
/**
3823
* {@inheritdoc}
3924
*/
@@ -69,61 +54,4 @@ public function getBlockPrefix()
6954
{
7055
return 'locale';
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(Locales::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/Tests/Extension/Core/Type/CountryTypeTest.php

-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
15-
use Symfony\Component\Form\Extension\Core\Type\CountryType;
1615
use Symfony\Component\Intl\Util\IntlTestHelper;
1716

1817
class CountryTypeTest extends BaseTypeTest
@@ -81,14 +80,4 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'FR', $expectedD
8180
{
8281
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
8382
}
84-
85-
/**
86-
* @group legacy
87-
*/
88-
public function testInvalidChoiceValuesAreDropped()
89-
{
90-
$type = new CountryType();
91-
92-
$this->assertSame([], $type->loadChoicesForValues(['foo']));
93-
}
9483
}

0 commit comments

Comments
 (0)