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] LetTextType implementDataTransformerInterface#18357

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

Merged

Conversation

HeahDude
Copy link
Contributor

QA
Branch?master
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#5906
LicenseMIT
Doc PR~

onlime and fsevestre reacted with thumbs up emojifsevestre and peter-gribanov reacted with hooray emojiMirakuSan reacted with eyes emoji
@HeahDudeHeahDudeforce-pushed thefeature-form-text_type-data_mapper branch 2 times, most recently from4ad7303 tof274178CompareMarch 30, 2016 06:37
@HeahDude
Copy link
ContributorAuthor

Failures unrelated.

@HeahDude
Copy link
ContributorAuthor

This goes in master, right ?

@javiereguiluzjaviereguiluz changed the title[Form] letTextType implementsDataTransformerInterface[Form] LetTextType implementDataTransformerInterfaceMar 30, 2016

$this->assertSame('', $form->getData());
}
}

Choose a reason for hiding this comment

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

Please add a newline at the end of this file. Thanks!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@javiereguiluz Nice catch! Thanks :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed.

@HeahDudeHeahDudeforce-pushed thefeature-form-text_type-data_mapper branch fromf274178 to2a66b4eCompareMarch 30, 2016 07:01
*/
public function reverseTransform($data)
{
return empty($data) ? '' : $data;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should benull === $data ? '' : $data, no ?
What happens if we submit0 ?

HeahDude reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@fsevestre Thanks! I've changed it will making the tests and forgot to revert it :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed!

closessymfony#5906.The submitted data should always betransformed back to the model as a stringas NULL in this case could stand for "unsetthis value" whereas a string property of aclass could rely on the string type.Furthermore, this prevents potential issueswith PHP 7 which allows type hinting ofstrings in functions.
@HeahDudeHeahDudeforce-pushed thefeature-form-text_type-data_mapper branch from2a66b4e to7e97fbbCompareMarch 30, 2016 07:45
'empty_data' => '',
));

$form->submit(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any config with the new system that allows one to distinguish betweensubmit(null) andsubmit('') in the model data?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87 I don't really understand what is "new" for you, as I am feeling quite new myself in symfony :)

  1. But as far as I understand when you callForm::submit(null) here what happens:

  2. So at this point view data cannot be an empty string, it remainsnull.

    Then:

  3. Hence here we do have a view data as empty string but...:

Conclusion

This PR could add a view data transformer toprevent that call but I guess in order to prevent messing with other transformers and as this has to stay the default,@webmozart asked to add it as a model data transformer since it is the first registered => also the last called => minimum of potential BC breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

with "new system" i was refering to the state of the form component after your PR.

i was specially talking about how to distinguish between a text field that is submitted with null vs submitted with empty string.

consider a simple form with text field:

$form =$factory->create();$form->add('name', TextType::class, ['required' =>false ]);

and now the different submits:

// 1.$form->submit(null);assert$form->get('name')->getData() ===null;// 2.$form->submit([]);assert$form->get('name')->getData() ===null;// 3.$form->submit(['name' =>null ]);assert$form->get('name')->getData() ===null;// 4.$form->submit(['name' =>'' ]);assert$form->get('name')->getData() ==='';// 5.$form->submit(['name' =>'Joe' ]);assert$form->get('name')->getData() ==='Joe';
  • name is truely optional here, but is also allowed to be the empty string (that is also different from "name not given")
    1. can be viewed as a submission error, though one could normalize it to[]

edit: this topic isnt directly related to your PR, but a general: "how does the TextType field work currently and is expected to work ideally". i mean there must be a reasoning to kill the empty string from the model value space of the text type.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87 Yes, the reasoning is to not break data transformers by passingnull instead of an empty string.

ConcerningTextType this PR does not introduce a "new" way, it just considers the setting ofempty_data which was ignored before.

This is a bug fix, I'm not sure it should go in master though.

ping@webmozart

@HeahDude
Copy link
ContributorAuthor

What is the status of this one ? It's been ready for 3.1 for a while :)

@HeahDude
Copy link
ContributorAuthor

ping :)

@fabpot
Copy link
Member

Thank you@HeahDude.

@fabpotfabpot merged commit7e97fbb intosymfony:masterApr 28, 2016
fabpot added a commit that referenced this pull requestApr 28, 2016
…ace` (HeahDude)This PR was merged into the 3.1-dev branch.Discussion----------[Form] Let `TextType` implement `DataTransformerInterface`| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#5906| License       | MIT| Doc PR        | ~Commits-------7e97fbb [Form] let `TextType` implements `DataTransformerInterface`
@HeahDudeHeahDude deleted the feature-form-text_type-data_mapper branchApril 28, 2016 10:44
@fabpotfabpot mentioned this pull requestMay 13, 2016
fabpot added a commit that referenced this pull requestMar 5, 2017
This PR was merged into the 2.7 branch.Discussion----------[Form] Hardened form type tests| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | ~| License       | MIT| Doc PR        | ~This one the PRs to come targeting 2.7 needed to harden the code base before doing some changes in master.It takes care of the form types tests part (even if some other tests will be added later, it will also be easier after it), and unlocks merging#21481.It also back ports tests added in#18357 for the TextType.Since it's very hard to merge branches when modifying tests because of BC, and making every test type extend the base type test would involve many function calls to get the tested type, the function `getTestedType` is no longer abstract and return a constant to override instead, it's much better for performance, I didn't change the call in the base type test to keep BC but I suggest to deprecate it in master. Even if those are tests I really think it is worth keeping BC here.The constants also ease testing in the ecosystem of form related libraries that need to be compatible with Symfony 2.7 and 3. I think using "test" as both prefix and suffix on namespaces, classes and names of the constants should discourage using them in real application code. Since this is just about our test suite, I don't think this should be considered a feature, so tis change should be good for 2.7.Two other PRs will follow to solve conflicts in 2.8 and 3.2.I missed last month patches, I hope I won't this time :).Commits-------8cfc3e9 [Form] Hardened form type tests
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestDec 8, 2018
…altsov)This PR was merged into the 3.4 branch.Discussion----------[Forms] Fixed TextType empty_data value explanation#SymfonyConHackDaySeesymfony/symfony#18357 that introduced a way to use an empty string in models, so setter does not have to be nullable. Usage example:https://github.com/EnMarche/en-marche.fr/blob/master/src/Form/TypeExtension/TextTypeExtension.php#L28Thanx to@HeahDude for helping me with this PR.Commits-------5cfff92 Fix TextType empty_data value explanation
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@HeahDude@fabpot@javiereguiluz@backbone87@fsevestre@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp