-
Notifications
You must be signed in to change notification settings - Fork 15
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
Made template for showing image_field in admin-ui more robust #1387
base: 4.6
Are you sure you want to change the base?
Conversation
Quality Gate passedIssues Measures |
@@ -447,7 +447,7 @@ | |||
<td>{{ 'ezimage.master_dimensions'|trans|desc('Master dimensions') }}:</td> | |||
<td>{{ 'ezimage.width_and_height'|trans({'%width%': field.value.width, '%height%': field.value.height})|desc('Width: %width%px height: %height%px') }}</td> | |||
</tr> | |||
{% if field.value.height != '0' %} | |||
{% if field.value.height != '0' and field.value.height != '' %} |
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.
This should achieve the same result:
{% if field.value.height != '0' and field.value.height != '' %} | |
{% if field.value.height %} |
However, the important bit is that what is in the block below relies on field.value.height
being "not zero", as we're performing a division. Non-empty string that does not contain a numerical value will cause PHP to error out.
As Fabien pointed out in the comments to the PR you linked, adding is_numeric
as a function/test to Twig is trivial and we can do that relatively easily.
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.
Yes, we need to keep the check for value 0
in order to avoid division by zero.
But we could change it to this indeed:
{% if field.value.height != '0' and field.value.height != '' %} | |
{% if field.value.height != '0' and field.value.height %} |
Or do you prefer I make a is numeric
test to Twig so it reads something like :
{% if field.value.height != '0' and field.value.height != '' %} | |
{% if field.value.height is numeric and field.value.height != '0' %} |
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.
@Steveb-p You want me to make a is numeric
test, or this is not needed ?
Description:
I was not able to reproduce the problem on a fresh 4.6, but on a installation just upgraded to 4.6 (was at some point using 2.5 or maybe even older releases) the database had a lot of images with the following "empty" data in
ezcontentobject_attribute.data_text
:In 4.6, the value will simply be
null
if no image is uploaded. However, in earlier versions it was obviously stored like shown above. And one problem here is thatheight
has a value set to empty string. The admin-ui template requiresheight
to be numeric or aUnsupported operand types: string / string
exception will be thrown.It would be nice if twig had a
is numeric
test but that is not going to happend. For this use-case it is sufficient to check if value is empty string tooFor QA:
Documentation: