-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] add "model_type" option to MoneyType #51884
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
eae8a80
to
dd0c07d
Compare
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.
Thanks Massimiliano for this improvement! I left a minor request.
src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php
Show resolved
Hide resolved
@xabbuh could you review, please? |
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.
Please add a line in the chagelog of the component in section 7.1
|
||
$resolver->setNormalizer('model_type', static function (Options $options, $value) { | ||
if ('integer' === $value && 1 === $options['divisor']) { | ||
throw new LogicException('Can use integer "model_type" option only when the "divisor" option is not 1.'); |
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.
throw new LogicException('Can use integer "model_type" option only when the "divisor" option is not 1.'); | |
throw new LogicException('When the "model_type" option is set to "integer", the "divisor" option should not be set to "1".'); |
but why?
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.
Because if you set the divisor to 1, you can end up with a float instead of an integer, and lose decimals in the casting
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'm sorry I don't get it. Also the original PR had exactly the opposite : throwing when the divisor is not 1.
https://github.com/symfony/symfony/pull/50720/files#diff-eb30dc48f2b749fa5d76ce9598bb51c00fcb97bd7a10337f0630db00f5ba3b9aR100
I'm pretty sure I'm missing something 😬
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 know, and indeed I added a note about that when I opened this PR.
I see no changelog for 7.1, should I create a new file? |
e5dfc53
to
8811741
Compare
Thank you @garak. |
This is a replacement for abandoned #50720
Please notice that the previous PR misunderstood the related issue: the intended casting should be applied when the divisor is not 1, otherwise it doesn't make sense.