From b8ac58c56ddf9687e6dd8c2573f2ae13070526c3 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 25 Jan 2018 11:35:56 +0300 Subject: [PATCH 1/5] mark usage of callable empty_data not instance of \Closure is deprecated --- .../Component/Form/Extension/Core/Type/ChoiceType.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index d9df942c6af30..920f549cf3205 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -91,7 +91,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) $emptyData = $form->getConfig()->getEmptyData(); if (false === FormUtil::isEmpty($emptyData) && array() !== $emptyData) { - $data = is_callable($emptyData) ? call_user_func($emptyData, $form, $data) : $emptyData; + if ($emptyData instanceof \Closure) { + $data = call_user_func($emptyData, $form, $data); + } elseif (is_callable($emptyData)) { + @trigger_error('Usage of callable empty_data not instance of Closure is deprecated since version 4.1 and will be removed in 5.0.', E_USER_DEPRECATED); + $data = call_user_func($emptyData, $form, $data); + } else { + $data = $emptyData; + } } } From f8cc14441167428609f52f46976c6eb4f27e2e2c Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 25 Jan 2018 11:59:14 +0300 Subject: [PATCH 2/5] allow use array as handler --- .../Component/Form/Extension/Core/Type/ChoiceType.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 920f549cf3205..3b90ac5bb4978 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -91,10 +91,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) $emptyData = $form->getConfig()->getEmptyData(); if (false === FormUtil::isEmpty($emptyData) && array() !== $emptyData) { - if ($emptyData instanceof \Closure) { - $data = call_user_func($emptyData, $form, $data); - } elseif (is_callable($emptyData)) { - @trigger_error('Usage of callable empty_data not instance of Closure is deprecated since version 4.1 and will be removed in 5.0.', E_USER_DEPRECATED); + if (is_callable($emptyData)) { + if (is_string($emptyData)) { + @trigger_error('Passing callable strings is deprecated is deprecated since version 4.1 and will be removed in 5.0.', E_USER_DEPRECATED); + } $data = call_user_func($emptyData, $form, $data); } else { $data = $emptyData; From 62d2c14c66c2f143f5642e956f94859a2642a782 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 25 Jan 2018 12:54:22 +0300 Subject: [PATCH 3/5] add info in UPGRADE and CHANGELOG. Add callable empty_data tests --- UPGRADE-4.1.md | 19 +++++++++ UPGRADE-5.0.md | 19 +++++++++ src/Symfony/Component/Form/CHANGELOG.md | 5 +++ .../Form/Extension/Core/Type/ChoiceType.php | 2 +- .../Extension/Core/Type/ChoiceTypeTest.php | 41 +++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) diff --git a/UPGRADE-4.1.md b/UPGRADE-4.1.md index b6b94be57aae2..372b2b84316fa 100644 --- a/UPGRADE-4.1.md +++ b/UPGRADE-4.1.md @@ -45,6 +45,25 @@ Validator * Calling `EmailValidator::__construct()` method with a boolean parameter is deprecated and will be removed in 5.0, use `EmailValidator("strict")` instead. * Deprecated the `checkDNS` and `dnsMessage` options of the `Url` constraint. They will be removed in 5.0. +Form +---- + + * Using callable strings as `empty_data` in `ChoiceType` has been deprecated in Symfony 4.1 use a `\Closure` instead. + + Before: + + ```php + 'empty_data' => 'SomeValueObject::getDefaultValue', + ``` + + After: + + ```php + 'empty_data' => function (FormInterface $form, $data) { + return SomeValueObject::getDefaultValue(); + }, + ``` + Workflow -------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index d4d2a49d481f6..edb170c46b3eb 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -42,6 +42,25 @@ Validator * Calling `EmailValidator::__construct()` method with a boolean parameter has been removed, use `EmailValidator("strict")` instead. * Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint. +Form +---- + + * Using callable strings as `empty_data` in `ChoiceType` has been deprecated in Symfony 4.1 use a `\Closure` instead. + + Before: + + ```php + 'empty_data' => 'SomeValueObject::getDefaultValue', + ``` + + After: + + ```php + 'empty_data' => function (FormInterface $form, $data) { + return SomeValueObject::getDefaultValue(); + }, + ``` + Workflow -------- diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 5d01cb38931c9..33e1883310c6c 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.1.0 +----- + + * Using callable strings as `empty_data` in `ChoiceType` has been deprecated in Symfony 4.1 use a `\Closure` instead. + 4.0.0 ----- diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 3b90ac5bb4978..8980487800144 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -93,7 +93,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (false === FormUtil::isEmpty($emptyData) && array() !== $emptyData) { if (is_callable($emptyData)) { if (is_string($emptyData)) { - @trigger_error('Passing callable strings is deprecated is deprecated since version 4.1 and will be removed in 5.0.', E_USER_DEPRECATED); + @trigger_error('Passing callable strings is deprecated since version 4.1 and will be removed in 5.0. You should use a "\Closure" instead.', E_USER_DEPRECATED); } $data = call_user_func($emptyData, $form, $data); } else { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 192d38f1a9225..e989e766feb5f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -640,6 +640,47 @@ public function testSubmitMultipleChoiceExpandedWithEmptyData() $this->assertSame(array('test'), $form->getData()); } + /** + * @group legacy + */ + public function testSubmitSingleChoiceWithCallableEmptyData() + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'multiple' => false, + 'expanded' => true, + 'choices' => array('test'), + 'empty_data' => __CLASS__.'::emptyDataResolver', + )); + + $form->submit(null); + + $this->assertSame('test', $form->getData()); + } + + /** + * @return string + */ + public static function emptyDataResolver() + { + return 'test'; + } + + public function testSubmitSingleChoiceWithClosureEmptyData() + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'multiple' => false, + 'expanded' => true, + 'choices' => array('test'), + 'empty_data' => function() { + return 'test'; + }, + )); + + $form->submit(null); + + $this->assertSame('test', $form->getData()); + } + public function testSubmitMultipleNonExpanded() { $form = $this->factory->create(static::TESTED_TYPE, null, array( From da3c6acddbc71e23fbc51f76df402cda71677dab Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 25 Jan 2018 12:56:48 +0300 Subject: [PATCH 4/5] fix CS --- .../Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index e989e766feb5f..21d9f2dbc4764 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -671,7 +671,7 @@ public function testSubmitSingleChoiceWithClosureEmptyData() 'multiple' => false, 'expanded' => true, 'choices' => array('test'), - 'empty_data' => function() { + 'empty_data' => function () { return 'test'; }, )); From eb95111f85486c5d33ad0a09ef25563f20d68a6a Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 25 Jan 2018 13:00:21 +0300 Subject: [PATCH 5/5] remove deprecated feature --- .../Form/Extension/Core/Type/ChoiceType.php | 5 +--- .../Extension/Core/Type/ChoiceTypeTest.php | 25 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 8980487800144..18fc217a2ab63 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -91,10 +91,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $emptyData = $form->getConfig()->getEmptyData(); if (false === FormUtil::isEmpty($emptyData) && array() !== $emptyData) { - if (is_callable($emptyData)) { - if (is_string($emptyData)) { - @trigger_error('Passing callable strings is deprecated since version 4.1 and will be removed in 5.0. You should use a "\Closure" instead.', E_USER_DEPRECATED); - } + if (is_callable($emptyData) && !is_string($emptyData)) { $data = call_user_func($emptyData, $form, $data); } else { $data = $emptyData; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 21d9f2dbc4764..18db447db3c5d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -640,31 +640,6 @@ public function testSubmitMultipleChoiceExpandedWithEmptyData() $this->assertSame(array('test'), $form->getData()); } - /** - * @group legacy - */ - public function testSubmitSingleChoiceWithCallableEmptyData() - { - $form = $this->factory->create(static::TESTED_TYPE, null, array( - 'multiple' => false, - 'expanded' => true, - 'choices' => array('test'), - 'empty_data' => __CLASS__.'::emptyDataResolver', - )); - - $form->submit(null); - - $this->assertSame('test', $form->getData()); - } - - /** - * @return string - */ - public static function emptyDataResolver() - { - return 'test'; - } - public function testSubmitSingleChoiceWithClosureEmptyData() { $form = $this->factory->create(static::TESTED_TYPE, null, array( 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