Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] TransformationFailedException: Support specifying message to display#20978
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
[Form] TransformationFailedException: Support specifying message to display#20978
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Exception/TransformationFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Exception/TransformationFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ogizanagi commentedJul 6, 2017
@HeahDude : Is it worth working again on this PR or should I wait your propositions about#20978 (comment) ? |
HeahDude commentedJul 6, 2017
Yes, I suggest to wait :). |
nicolas-grekas commentedOct 8, 2017
Moving to 4.1. Rebase on master needed, where PHP 7.1 features can be used btw. |
fabpot commentedMar 31, 2018
@HeahDude Any ways we can unblock this PR? |
xabbuh commentedSep 15, 2018
What about allowing the option to be a closure that would get passed the transformation failure exception and would return the error message to use? |
ogizanagi commentedSep 15, 2018
@xabbuh : Would you remove the safe message in favor of more specific |
xabbuh commentedOct 9, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
After thinking about it again I think having a message key in the exception isn't such a bad idea. It's also consistent with what we support in the Security component. |
ogizanagi commentedNov 5, 2018
Woops. I've closed this one by mistake. |
nicolas-grekas commentedNov 8, 2018
rebase needed. for which branch is this PR? |
ogizanagi commentedNov 9, 2018
Rebased on master |
src/Symfony/Component/Form/Exception/TransformationFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Form/Form.php Outdated
| } | ||
| }catch (TransformationFailedException$exception) { | ||
| thrownewTransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'":'.$exception->getMessage(),$exception->getCode(),$exception); | ||
| thrownewTransformationFailedException( |
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.
should be kept on one line
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.
also, not sure if we really need this change
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.
not sure if we really need this change
Well, we need to forward the invalid message and parameters to the new exception, otherwise it's just vanished. What did you mean?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fabpot commentedMar 24, 2019
@ogizanagi@HeahDude I think we need to take a decision here. Finish/merge or close? |
ogizanagi left a comment
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.
I still think this is valuable and doesn't bring much complexity.
src/Symfony/Component/Form/Form.php Outdated
| } | ||
| }catch (TransformationFailedException$exception) { | ||
| thrownewTransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'":'.$exception->getMessage(),$exception->getCode(),$exception); | ||
| thrownewTransformationFailedException( |
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.
not sure if we really need this change
Well, we need to forward the invalid message and parameters to the new exception, otherwise it's just vanished. What did you mean?
ogizanagi commentedMar 26, 2019
(PR rebased) |
fabpot commentedMar 27, 2019
Thank you@ogizanagi. |
…ng message to display (ogizanagi)This PR was merged into the 4.3-dev branch.Discussion----------[Form] TransformationFailedException: Support specifying message to display| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#22501| License | MIT| Doc PR | N/ACurrently, a failed transformation can't display a very accurate message, as it only uses the value of the `invalid_message` option. I suggest to add more flexibility, somehow the same way we did for `CustomUserMessageAuthenticationException`.A test case in `FormTypeTest` shows a use-case based on@webmozart's [blog post about value/immutable objects in Symfony forms](https://webmozart.io/blog/2015/09/09/value-objects-in-symfony-forms/).~I named the exception properties and methods the same way as for `CustomUserMessageAuthenticationException`, but do you think the followings would be better:~- ~`setSafeMessage` ➜ `setInvalidMessage`~- ~`getMessageKey` ➜ `getInvalidMessageKey`~- ~`getMessageData` ➜ `getInvalidMessageParameters`~~in order to echoes `invalid_message` and `invalid_message_parameters` options?~=> Replaced to use `invalidMessage` & `invalidMessageParameters`Commits-------d11055c [Form] TransformationFailedException: Support specifying message to display
Uh oh!
There was an error while loading.Please reload this page.
Currently, a failed transformation can't display a very accurate message, as it only uses the value of the
invalid_messageoption. I suggest to add more flexibility, somehow the same way we did forCustomUserMessageAuthenticationException.A test case in
FormTypeTestshows a use-case based on@webmozart'sblog post about value/immutable objects in Symfony forms.I named the exception properties and methods the same way as forCustomUserMessageAuthenticationException, but do you think the followings would be better:setSafeMessage➜setInvalidMessagegetMessageKey➜getInvalidMessageKeygetMessageData➜getInvalidMessageParametersin order to echoesinvalid_messageandinvalid_message_parametersoptions?=> Replaced to use
invalidMessage&invalidMessageParameters