-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add default transformer to TextType field (and related) #2421
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
Conversation
} | ||
|
||
/** | ||
* Transforms a string into a Boolean. |
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.
really? :)
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.
Copy&paste rulz!!!oneoneone... ;-) Will replace later on :-)
@fabpot ping ;-) |
Is it really needed? I have a feeling that it enforces unneeded constraints, but I can be wrong of course. |
It's needed because with TextType field, and without the ValueToStringTransformer, the user data (when sending the form) can be an array !!! For example:
|
Commits ------- 49d2685 [Form] Add default validation to TextType field (and related) Discussion ---------- [Form] Add default transformer to TextType field (and related) Bug fix: yes&no (?) Feature addition: yes (?) BC break: no Symfony2 tests pass: yes Fixes the following tickets: #1962. --------------------------------------------------------------------------- by stloyd at 2011/12/19 03:43:37 -0800 @fabpot ping ;-) --------------------------------------------------------------------------- by fabpot at 2011/12/19 10:58:20 -0800 Is it really needed? I have a feeling that it enforces unneeded constraints, but I can be wrong of course. --------------------------------------------------------------------------- by hlecorche at 2011/12/20 02:31:03 -0800 It's needed because with TextType field, and without the ValueToStringTransformer, the user data (when sending the form) can be an array !!! For example: - if there is a TextType field - and if there is a MaxLengthValidator - and if the user data (when sending the form) is an array So the exception "Expected argument of type string, array given in src\Symfony\Component\Validator\Constraints\MaxLengthValidator.php at line 40" is thrown
This happens to break other client transformers, for instance a text field accepting a user name, with a UsernameToUserTransformer converting the user name to a user instance, wouldn't work anymore (example: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Form/DataTransformer/UsernameToUserTransformer.php ) |
I've sent a PR adding a test for this regression: #3016 |
public function transform($value) | ||
{ | ||
if (null === $value) { | ||
return ''; |
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.
Don't know if that's expected, but there is a little behavior change here.
Before adding this data transformer, empty strings were converted to NULL. It's not the case anymore.
Form::clientToNorm() returns NULL if the value is an empty string, if there is no client transformer.
Now that this client transformer is added by default on TextType, empty strings are not longer transformed to NULL.
What's the point of this addition? @hlecorche Why should the browser submit an array? |
@bschussek A pirate or a bad behavior can send an array... and a error 500 is thrown... |
Ok, thanks for the answer. See the referenced ticket for more information. |
Bug fix: yes&no (?)
Feature addition: yes (?)
BC break: no
Symfony2 tests pass: yes
Fixes the following tickets: #1962.