Problem/Motivation

  • We need support for sizes, this will primarily be used by picture, but contrib can use this as well in combination with srcset

Proposed resolution

  • Add sizes attribute to image render

Remaining tasks

  • Add tests for sizes

User interface changes

None

Comments

jelle_s’s picture

Title: Add srcset to template_preprocess_imagesizes » Add sizes to template_preprocess_image
jelle_s’s picture

Assigned: jelle_s » Unassigned
Status: Active » Needs review
StatusFileSize
new3.15 KB
attiks’s picture

Status: Needs review » Reviewed & tested by the community

Assuming test bot is fine with it.

attiks’s picture

attiks’s picture

Issue summary: View changes
webchick’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/system/src/Tests/Theme/ImageTest.php
    @@ -0,0 +1,49 @@
    +class ImageTest extends DrupalUnitTestBase {
    

    Once again, should be KernelTestBase.

  2. +++ b/core/modules/system/src/Tests/Theme/ImageTest.php
    @@ -0,0 +1,49 @@
    +   * Tests that an image with the srcset and widths is output correctly.
    ...
    +    $this->assertRaw($expected, 'Correct output for image with srcset attribute and width descriptors.');
    

    It does not actually test srcset.

Also, suggestion from dawehner in IRC on the test itself (this would also apply to the srcset issue):

<dawehner> checking for exact HTML output is a bad idea
<dawehner> I would suggest to better parse the HTML and look at it
<dawehner> use $this->drupalSetRawContent() and then get the dom element and look at it
<dawehner> for example the order of the attributes could change easily which doesn't matter here at all

Since both this and the other patch are going to smack into each other, if you want to combine them into one, feel free.

attiks’s picture

AFAIK it uses the same principle as the image module for testing, so we need issues to update those tests as well, @dawehner is right that testing HTML is a bit lame.

attiks’s picture

Status: Needs work » Needs review
StatusFileSize
new2.83 KB

New test, since xpath is not working (#2335057: Undefined method getUrl in AssertContentTrait::parse causes fatal error) is uses assertRaw.

rainbowarray’s picture

Issue tags: +Needs reroll

Patch doesn't apply. Needs reroll.

This test looks much better, though. I thought I remember seeing something about calc possibly not working within a sizes attribute. It would be good to verify that before we use it in a test.

jelle_s’s picture

StatusFileSize
new2.86 KB

Rerolled, and removed calc within the sizes attribute.

jelle_s’s picture

Issue tags: -Needs reroll
attiks’s picture

Status: Needs review » Reviewed & tested by the community

Assuming test bot will be happy, this is RTBC.

The issue to test the real DOM is still a valid point, but can be solved in a follow up.

rainbowarray’s picture

For what it's worth, found out you can use calc within sizes. But we don't need that in the test, so this still looks good to go for me.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed bb3ee20 and pushed to 8.0.x. Thanks!

  • alexpott committed bb3ee20 on 8.0.x
    Issue #2333395 by Jelle_S, attiks: Add sizes to...
yched’s picture

Minor: test comment says "test with multipliers", while this is not what the test does.

yched’s picture

Also, would have been nice sugar to accept sizes as an array of strings, not requiring callers to do the implode themselves ?

attiks’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.