Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@peter-gribanov
Copy link
Contributor

@peter-gribanovpeter-gribanov commentedJan 25, 2018
edited
Loading

QA
Branch?4.1
Bug fix?no
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
LicenseMIT

This PR is related to bug#25896, but doesn't solve it.

derrabus reacted with thumbs up emoji
@peter-gribanovpeter-gribanov changed the titleEmpty data callable deprecated[Form] Empty data callable deprecatedJan 25, 2018
@peter-gribanovpeter-gribanov changed the title[Form] Empty data callable deprecated[Form] Deprecate a callable empty_data in ChoiceTypeJan 25, 2018
@xabbuhxabbuh added this to the4.1 milestoneJan 25, 2018
@xabbuhxabbuh added the Form labelJan 25, 2018
```php
'empty_data' => function (FormInterface $form, $data) {
return SomeValueObject::getDefaultValue();
},
Copy link
Member

@derrabusderrabusJan 25, 2018
edited
Loading

Choose a reason for hiding this comment

The 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['SomeValueObject', 'getDefaultValue']and I personally would prefer that notation over an anonymous function.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

And in vain you prefer such a call to static functions.
This leads to the fact that the connection to the real function is lost and this is guaranteed to lead to problems during refactoring.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Form
----

* Using callable strings as`empty_data` in`ChoiceType` has been deprecated in Symfony 4.1 use a`\Closure` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Should be:

* Support for callable strings as `empty_data` in `ChoiceType` has been removed. Use a `\Closure` instead.

Form
----

* Using callable strings as`empty_data` in`ChoiceType` has been deprecated in Symfony 4.1 use a`\Closure` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Better:… is deprecated and will be removed in Symfony 5.0, use a…

4.1.0
-----

* Using callable strings as`empty_data` in`ChoiceType` has been deprecated in Symfony 4.1 use a`\Closure` instead.
Copy link
Member

Choose a reason for hiding this comment

The 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:

* deprecated support for callable strings as `empty_data` in `ChoiceType`

@derrabus
Copy link
Member

Maybe we should addFileType (as mentioned in#25896 (comment)) to this PR. It seems odd to deprecate that mechanism for one type, but leave it active for another.

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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
But I've made a mistake, IMO we should do it likehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L610 and merge it in 2.7 as bug fix too. No need to deprecate anything.

Copy link
Member

Choose a reason for hiding this comment

The 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. :-(

Copy link
Member

Choose a reason for hiding this comment

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

Also, I would not check forinstanceof \Closure as this would forbid array callables and invokable objects for no reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Theempty_data MUST be a closure for all forms, I'm not sure people rely on this hidden feature which is just a bug I introduced no matter when IMO.

peter-gribanov reacted with thumbs up emoji
@peter-gribanov
Copy link
ContributorAuthor

Maybe we should addFileType (as mentioned in#25896 (comment)) to this PR.

@derrabus sorry, but i would prefer to see this in another PR.

derrabus reacted with thumbs up emoji

After:

```php
'empty_data' => function (FormInterface $form, $data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Or justClosure::fromCallable('some_function') 😉

@fabpot
Copy link
Member

Closing in favor of#25948

@fabpotfabpot closed thisFeb 1, 2018
fabpot added a commit that referenced this pull requestFeb 1, 2018
…e (HeahDude)This PR was merged into the 2.7 branch.Discussion----------[Form] Fixed empty data on expanded ChoiceType and FileType| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#25896| License       | MIT| Doc PR        | ~Alternative of#25924.I don't think we have to do this by adding overhead in master and getting it properly fixed in 2 years.This is bug I've introduced while fixing another bug#17822. Which then has been replicated in#20418 and#24993.I propose instead to clean up the code for all LTS, since this is a wrong behaviour that has never been documented, and most of all unreliable.The `empty_data` can by anything in the view format as long as the reverse view transformation supports it. Even an object derived from the data class could be invokable.I think we should remain consistent withhttps://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Form.php#L615.Commits-------9722c06 [Form] Fixed empty data on expanded ChoiceType and FileType
symfony-splitter pushed a commit to symfony/form that referenced this pull requestFeb 1, 2018
…e (HeahDude)This PR was merged into the 2.7 branch.Discussion----------[Form] Fixed empty data on expanded ChoiceType and FileType| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | #25896| License       | MIT| Doc PR        | ~Alternative ofsymfony/symfony#25924.I don't think we have to do this by adding overhead in master and getting it properly fixed in 2 years.This is bug I've introduced while fixing another bug #17822. Which then has been replicated in #20418 and #24993.I propose instead to clean up the code for all LTS, since this is a wrong behaviour that has never been documented, and most of all unreliable.The `empty_data` can by anything in the view format as long as the reverse view transformation supports it. Even an object derived from the data class could be invokable.I think we should remain consistent withhttps://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Form.php#L615.Commits-------9722c063fb [Form] Fixed empty data on expanded ChoiceType and FileType
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@derrabusderrabusderrabus approved these changes

+2 more reviewers

@KocKocKoc left review comments

@HeahDudeHeahDudeHeahDude left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

7 participants

@peter-gribanov@derrabus@fabpot@Koc@HeahDude@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp