Skip to content

[Form] added a test for TextType with custom data transformers #3016

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

Closed
wants to merge 1 commit into from

Conversation

arnaud-lb
Copy link
Contributor

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: no (expected)

This tests if TextType works well with DataTransformers that transform from and to non-string values.

@fabpot
Copy link
Member

fabpot commented Jan 2, 2012

see #2421 for the original PR that changed the behavior.

@stloyd: Can you have a look at this side-effect?

@fabpot
Copy link
Member

fabpot commented Jan 22, 2012

@stloyd: I' m about to revert #2421. Have you had time to look into this?

@stof
Copy link
Member

stof commented Jan 28, 2012

@fabpot any news about the revert ?

We just found that the change broke the custom type in FOSUserBundle as it inherits from text and add a transformer

@jmikola
Copy link
Contributor

jmikola commented Jan 28, 2012

@fabpot: @stof is referring to FriendsOfSymfony/FOSUserBundle@6cbe4da. A user of OrnicarMessageBundle alerted me to this issue.

My commit message above mentions two possible solutions. Either inheriting field types clear the text type's transformer chain before appending their own, or transformers are rewritten to no-op for empty strings in addition to null. I was in favor of the former option.

Regarding #2421: Throwing an UnexpectedTypeException for non-string and non-numeric values (e.g. arrays, objects) seems like a non-essential convenience for the developer. The alternative is that you might end up seeing Array or an object's string representation printed in a text input field. I don't think it's too much to ask that developers catch that themselves -- and who's to say someone might not want to original behavior? Lastly, the role of the text type as a common parent should lead us to be very conservative about restricting its functionality.

@webmozart
Copy link
Contributor

The given test is invalid. You should use prependClientTransformer(), otherwise your transformer is chained after ValueToStringTransformer which already converted the value to a string.

@webmozart webmozart closed this Feb 1, 2012
@jmikola
Copy link
Contributor

jmikola commented Feb 2, 2012

@bschussek: If FOSUserBundle's UsernameToUserTransformer transformer was prepended to the stack (ahead of ValueToStringTransformer), I assume UsernameToUserTransformer::transform() would execute before ValueToStringTransformer::transform().

During reverse transformation, would ValueToStringTransformer::reverseTransform() be called first?

@webmozart
Copy link
Contributor

Exactly.

@webmozart
Copy link
Contributor

Btw, to keep heads from exploding, I suggest to rename it to UserToUsernameTransformer too, it makes things easier.

@arnaud-lb
Copy link
Contributor Author

@bschussek, if that's expected BC break, then it should be documented in UPGRADE :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants