-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Deprecate a callable empty_data in ChoiceType #25924
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
Changes from 8 commits
96e194c
b8ac58c
f8cc144
62d2c14
da3c6ac
db28aef
734fce1
3d19d31
6173596
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
---- | ||
|
||
* Support for callable strings as `empty_data` in `ChoiceType` has been removed. Use a `\Closure` instead. | ||
|
||
Before: | ||
|
||
```php | ||
'empty_data' => 'some_function', | ||
``` | ||
|
||
After: | ||
|
||
```php | ||
'empty_data' => function (FormInterface $form, $data) { | ||
return some_function($form, $data); | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, you should rather use a global function call as an example. A static method call can still be written as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And in vain you prefer such a call to static functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it was not my intention to discuss my personal preferences. Shouldn't have mentioned it. Still, the static call adds unnecessary distraction to the example, imho. |
||
``` | ||
|
||
Workflow | ||
-------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version information is redundant. To match the message style of other entries in this file, I'd suggest:
|
||
|
||
4.0.0 | ||
----- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 (is_callable($emptyData)) { | ||
if (is_string($emptyData)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've introduced that change as a bug fix in #17822 targeting 2.7. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #17822 is over 1.5y old now. People might have built code against that "feature" already. :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I would not check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
@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 { | ||
$data = $emptyData; | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just
Closure::fromCallable('some_function')
😉