Skip to content
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

Open
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '' %}
Copy link
Contributor

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:

Suggested change
{% 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.

Copy link
Contributor Author

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:

Suggested change
{% 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 :

Suggested change
{% if field.value.height != '0' and field.value.height != '' %}
{% if field.value.height is numeric and field.value.height != '0' %}

Copy link
Contributor Author

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 ?

<tr class="ibexa-field-preview__meta-value-row">
<td>{{ 'ezimage.ratio'|trans|desc('Ratio') }}:</td>
<td>{{ (field.value.width/field.value.height)|round(2) }}</td>
Expand Down
Loading