-
Notifications
You must be signed in to change notification settings - Fork 142
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
Fix behavior of PhoneNumberToStringTransformer #1
Fix behavior of PhoneNumberToStringTransformer #1
Conversation
The current implementation of PhoneNumberToStringTransformer::reverseTransform is incorrect: for each given string it should either return null or an instance of PhoneNumber. If an error occurs while parsing the phone number, the transformer should throw a TransformationFailedException. This will also automatically trigger the Form component to display a validation error. The fact that it currently returns the input string when it can't parse it leads to strange behavior, especially when mapping to a property that is mapped as a doctrine phone_number type.
ping @thewilkybarkid. |
Sorry for not looking this sooner. You right in that the exception should be thrown; the (slight) downside is that it doesn't seem to hit the validation constraint (ie the message returned now is the generic 'This value is not valid' rather than a friendlier 'This value is not a valid phone number'). Not sure if there's a solution... |
Right, good point. I think this can be fixed with the |
@thewilkybarkid I added the invalid message which is used by the validator extension of the form component to render the error message when transformation failed. |
👍 Thanks. |
Fix behavior of PhoneNumberToStringTransformer
Thanks for merging! :) While you're at it, could you tag a 1.0.0 release? |
Sorted! 😃 I had initially been waiting to see if the libphonenumber library was going to survive, seems to be ok! |
The current implementation of
PhoneNumberToStringTransformer::reverseTransform
is incorrect: for each given string it should either returnnull
or an instance ofPhoneNumber
. If an error occurs while parsing the phone number, the transformer should throw aTransformationFailedException
. This will also automatically trigger the Form component to display a validation error.The fact that it currently returns the input string when it can't parse it leads to strange behavior, especially when mapping to a property that is mapped as a doctrine phone_number type.