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

Fix EZP-24535: Avoid empty width/height and allow to force them #1300

Merged
merged 1 commit into from Jun 30, 2015
Merged

Fix EZP-24535: Avoid empty width/height and allow to force them #1300

merged 1 commit into from Jun 30, 2015

Conversation

Plopix
Copy link
Contributor

@Plopix Plopix commented Jun 11, 2015

  • Avoid the width="" and the height=""
  • Allow to force a height and a width manually (useful for handling the different screen densities)

@@ -410,6 +410,7 @@
<figure {{ block( 'field_attributes' ) }}>
{% set imageAlias = ez_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %}
<img src="{% if imageAlias %}{{ asset( imageAlias.uri ) }}{% else %}//:0{% endif %}"{% if imageAlias.width is defined %} width="{{ imageAlias.width }}"{% endif %}{% if imageAlias.height is defined %} height="{{ imageAlias.height }}"{% endif %} alt="{{ field.value.alternativeText }}" />
<img src="{% if imageAlias %}{{ asset( imageAlias.uri ) }}{% else %}//:0{% endif %}"{% if parameters.width is defined %} width="{{ parameters.width }}" {% endif %}{% if parameters.height is defined %} height="{{ parameters.height }}" {% endif %}{% if parameters.width is not defined and imageAlias.width is defined and imageAlias.width is not null %} width="{{ imageAlias.width }}"{% endif %}{% if parameters.height is not defined and imageAlias.height is defined and imageAlias.height is not null %} height="{{ imageAlias.height }}"{% endif %} alt="{{ field.value.alternativeText }}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better to set a height and width variable before this line in own set, picking parameter first if set, then alias if not null, and last fall back being null, hence simplifying the logic on this line and improving readability overall.

and besides I guess you meant to remove the original line? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH! Yes.. I'll do that tonight ;)

And ok for the set statement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A {spaceless} block might make this more readable, maybe.

@Plopix
Copy link
Contributor Author

Plopix commented Jun 15, 2015

Ok guys I think it's better

@andrerom it did create a var for the src too.
@bdunogier the spaceless was already in there.

{% set src = imageAlias ? asset( imageAlias.uri ) : "//:0" %}
{% set width = parameters.width is defined ? parameters.width : imageAlias.width %}
{% set height = parameters.height is defined ? parameters.height : imageAlias.height %}
<img src="{{ src }}"{% if width is not null %} width="{{ width }}"{% endif %}{% if height is not null %} height="{{ height }}"{% endif %} alt="{{ field.value.alternativeText }}" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{% if width %} might suffice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he did this on purpose, he is tackling several issues here actually. So should probably update description to clarify that.

@Plopix code is not checking imageAlias.width is defined anymore, guess it is always defined but might be null or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lolautruche, yes you're right according to the twig documentation I agree it's not required.
I can remove the "is not null", I wanted to enforce that as you asked for readability and because I thought you would have asked for it ;)

@andrerom Yes it's always defined. That's what I figured out and that's why we have today width="" height="" in the rendered source. It's normal as the property is always defined.

Then my description was (for me) complete, we avoid the empty width and we allow the developer to force the width/height with parameters.

Let me know if you want me to remove the "is not null"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you want me to remove the "is not null"

you can do that, no need to be so explicit in templates unless you have to :) 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ;)

@andrerom
Copy link
Contributor

+1, bon :)

@yannickroger
Copy link
Contributor

+1 looks good
Don't we need an issue for this ? (this need to be sent to the doc team).
Also the commit message needs to be updated.

@andrerom
Copy link
Contributor

Since it is core: yes
Also good for backport to 5.4 and 5.3.

@yannickroger
Copy link
Contributor

ping @Plopix
Can you create a jira issue and update your commit message. Then you can ping me and I'll merge it.

@Plopix
Copy link
Contributor Author

Plopix commented Jun 29, 2015

- Avoid the width="" and the height=""
- Allow to force a height and a width manually (useful for handling the different screen densities)
@Plopix Plopix changed the title Allow forcing the with/height and fix the test. Fix EZP-24535: Avoid empty width/height and allow to force them Jun 29, 2015
@Plopix
Copy link
Contributor Author

Plopix commented Jun 29, 2015

Done @yannickroger. Hope I did everything right ;-)

@yannickroger
Copy link
Contributor

@Plopix Thanks

yannickroger added a commit that referenced this pull request Jun 30, 2015
Fix EZP-24535: Avoid empty width/height and allow to force them
@yannickroger yannickroger merged commit 06c571d into ezsystems:master Jun 30, 2015
@yannickroger
Copy link
Contributor

Damn I just noticed that the comment above (line 404) has not been updated…

@yannickroger
Copy link
Contributor

@Plopix Do you have time to open a PR fixing the comment or should I do it quickly ?

@yannickroger
Copy link
Contributor

Check out #1320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants