-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Replace boolean cast to be able to disable frame, aspect ratio, trans… #7262
Conversation
…parency or constrain only in view.xml If you set frame to false in view.xml the code would cast it to true because (bool)'false' is equal to true. By using the filter_var function the cast to boolean is done correctly.
This will fix issue #4622 |
@@ -278,7 +278,7 @@ public function getQuality() | |||
*/ | |||
public function setKeepAspectRatio($keep) | |||
{ | |||
$this->_keepAspectRatio = (bool)$keep; | |||
$this->_keepAspectRatio = filter_var($keep, FILTER_VALIDATE_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.
Would something like
$this->_keepAspectRatio = $keep && $keep !== 'false';
do the trick and make an intention clearer for somebody who read the code? ;)
@orlangur It is indeed a better way. I have changed it. |
@orlangur Is this PR going to be merged? |
@Ctucker9233 I believe yes, as it's still perfect :) Cannot do it by myself, here you can track the progress of PR processing: https://github.com/magento/magento2/projects/3 It will take some time to process all old PRs, if you really need this fix in next release please ping somebody from Magento team. Cannot evaluate severity of this issue by myself. |
@magento-team Would like to request that this PR be merged. |
@Ctucker9233 @joost-florijn-kega PR have been merged into the |
@@ -278,7 +278,7 @@ public function getQuality() | |||
*/ | |||
public function setKeepAspectRatio($keep) | |||
{ | |||
$this->_keepAspectRatio = (bool)$keep; | |||
$this->_keepAspectRatio = $keep && $keep !== 'false'; |
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.
Actually, you could probably just do a json_decode($keep) here..
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.
Even if json_decode
works it would be much slower and much less clear.
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.
Yeah, point well-taken 👍
…parency or constrain only in view.xml
If you set frame to false in view.xml the code would cast it to true because
(bool)'false'
is equal totrue
. By using thefilter_var
function the cast to boolean is done correctly.