Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
- We need support for srcset, this will be used by picture, but contrib can use this as well to output an image with srcset.
Proposed resolution
- Add
srcset
attribute to image render
Remaining tasks
Add tests for srcset
User interface changes
None
Comment | File | Size | Author |
---|---|---|---|
#61 | i2262863-61.patch | 5.95 KB | Jelle_S |
#23 | interdiff.txt | 2.31 KB | Jelle_S |
#23 | i2262863-image-srcset-23.patch | 8.52 KB | Jelle_S |
Comments
Comment #1
attiks CreditAttribution: attiks commentedWIP, but first patch
Comment #2
attiks CreditAttribution: attiks commentedComment #3
attiks CreditAttribution: attiks commentedNew patching adding transformMimeType to all effects
Comment #5
attiks CreditAttribution: attiks commentedComment #7
attiks CreditAttribution: attiks commentedComment #8
attiks CreditAttribution: attiks commentedComment #9
andypostI think there's no reason to introduce API change here, so just add a new attribute and test for it
!empty() is enough
It's not clear the reason to introduce API change here?
Comment #10
attiks CreditAttribution: attiks commentedThe change is needed because an image style might change the file format (ex. from png to jpg), we need to know this so we can output the correct type on the source tag of picture.
Comment #11
attiks CreditAttribution: attiks commentedWe need some additions to the image module to support responsive images (picture):
Comment #12
attiks CreditAttribution: attiks commented!empty() is enough
Comment #13
andypostThis is API addition, updated summary.
except tests this one needs at least one usage in core
@attiks please check summary
suppose this one should be added to interface as well
Comment #14
attiks CreditAttribution: attiks commentedComment #15
attiks CreditAttribution: attiks commentedIs that mandatory?
Comment #16
attiks CreditAttribution: attiks commentedIt is
Comment #17
andypostNo, I mean
ImageStyleInterface
should be updated with the new public method tooComment #18
attiks CreditAttribution: attiks commentedComment #19
Jelle_SAdded tests for transformMimeType().
Comment #20
Jelle_SComment #21
yched CreditAttribution: yched commentedWhy both isset() and !empty() ? The latter should be enough ?
The base/default implementation coul be "just leave the $mime_type untouched", instead of forcing 99% effects to override that one ?
Comment #22
attiks CreditAttribution: attiks commented#21:
1/ Bad habits from the past, I'll fix it
2/ TRUE, but transformDimensions does somethin similar, so we kept it the same, I'll (or Jelle_S) change it as well
Comment #23
Jelle_S$variables
array, as you can provide default values for each key. But since the 'srcset' key contains an array with multiple srcsets, there are no default values for those keys, so bothisset()
and!empty()
are necessary to prevent PHP notices.Comment #26
attiks CreditAttribution: attiks commentedNew patch split from #2260061-98: Responsive image module does not support sizes/picture polyfill 2.2
Comment #27
RainbowArrayThis is probably a dumb question because I don't understand things, but why I are we creating a method just to wrap around the service call?
Is that for use in ImageStyleTest?
Comment #28
attiks CreditAttribution: attiks commented#27 It is for testing
Comment #29
Jelle_S#2260061-89: Responsive image module does not support sizes/picture polyfill 2.2 point 3 and #2260061-93: Responsive image module does not support sizes/picture polyfill 2.2
So basically, yes it is for use in ImageStyleTest. This way we don't have to mock the container in a UnitTest (which apparently is a big no-no :-) )
Comment #30
yched CreditAttribution: yched commentedNitpicks below
Var names could be worked on a bit here.
- This translates the info in $variable['srcset'] into an $srcsets array suitable for an 'srcset' HTML attribute. Why is one singular and the other plural ? Those two things contain the same info in different shapes.
- "foreach (srcset as srcset)" is a bit weird. Strictly speaking, an element of an "srcset" is an "src" ? or a "source" ?
- We don't need to assign back $srcset['src'], it is never used, so why not just $new_dource = file_create_uri(...) ?
- "new" in $new_source is not really needed, it's the source string we're building in this iteration of the foreach. There is no "old" source here.
Misses an article to be an actual sentence
Comment #31
Jelle_SNew patch with remarks from #30 addressed.
Comment #32
yched CreditAttribution: yched commentedThanks!
I don't see where the mimetype part of the patch gets used though ? AFAIK, the 'type' attribute is only for
<source>
tags within apicture
, not for srcset on<img>
tags, so this seems out of scope here ?Comment #33
attiks CreditAttribution: attiks commented@yched you're right it is not used, do we have to split this patch in two parts?
Comment #34
yched CreditAttribution: yched commentedWell, or keep the mimetype part for a patch that does add support for the 'type' attribute on sources in theme_responsive_image() ?
Comment #35
attiks CreditAttribution: attiks commentedMIME type split into new issue #2330899: Allow image effects to change the MIME type + extension, add a "convert" image effect
Comment #36
Jelle_SNew patch without the MIME type stuff, and with an added test.
Comment #38
yched CreditAttribution: yched commentedNot sure "outputted" is actual english ?
Other than that, looks good when green :-)
Comment #39
attiks CreditAttribution: attiks commented#38 Outputted is the paste tense of output, so it should be good. It is used in other places as well.
Comment #40
Jelle_SAlthough "outputted" is actual english, preference seems to go to just "output" (http://english.stackexchange.com/questions/35418/past-tense-of-to-output...), so I changed it just to be on the safe side.
Comment #41
RainbowArrayYou could replace output with processed as another option.
Comment #42
yched CreditAttribution: yched commentedThanks. Language can be adjusted on commit if deemed necessary.
Comment #43
Jelle_SComment #44
Jelle_SFYI: I also created #2333395: Add sizes to template_preprocess_image
Comment #45
attiks CreditAttribution: attiks commentedComment #46
webchickMinor grammar thing: URIs, not URI's. ;) http://theoatmeal.com/comics/apostrophe
I can fix this on commit, but...
Reading through http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#attr-... it says:
The
src
attribute must be present.The
srcset
attribute may also be present.(emphasis mine)
So why did we turn variables['attributes']['src'] into an optional variable here?
Yay! Tests! That's great.
However, AFAIK DUTB is being phased out in favor of KernelTestBase: https://www.drupal.org/node/1829160
Unfortunate that we need this method call, and render() doesn't just do what you would expect. :( Is that a separate bug somewhere?
Comment #47
webchickBased on dawehner's comments on the sizes issue, this is actually needs work for the test.
Comment #48
attiks CreditAttribution: attiks commented#46
You're right, but we need to be able to suppress the output of the src attribute, because otherwise all the prefetchers will start downloading the src, the only way to avoid this is to output only the srcset attribute.
Comment #49
attiks CreditAttribution: attiks commentedFYI: Another possible solution is to output an empty image as src, but this can only be done once #1342504: Support data URIs gets committed
Comment #50
Jelle_SChanged the test. I didn't want to change anything about the src attribute being optional or not until we can decide on #48 or #49.
Comment #51
RainbowArrayI just checked with the responsive images community group that came up with the picture element, and yes, while spec says that the img inside picture should always have src, that results in a double download with browsers that don't understand picture. So to make everything groovy when using this in conjunction with Picturefill, no src on the img inside picture. We're going to close our eyes, stick our fingers in our ears, go la la la la, and save the old browsers from two downloads. :)
Comment #52
webchickThat's a fair explanation, but is that relevant for D8? What "old browsers" are we supporting in D8? Or does IE9 count as an "old browser" in this context?
Comment #53
attiks CreditAttribution: attiks commentedOld browsers are all IE version and safari, chrome 38 will have native support as well as the next Firefox release.
Comment #54
Jelle_SIn addition to #53:
It seems that in Firefox you'll have to enable a flag: http://caniuse.com/#feat=srcset
Also iOS Safari will only support srcset in iOS8 (To be fair, most people will probably have updated by the time Drupal 8 releases)
The biggest group will probably be the IE users and the Firefox users who haven't enabled the flag for srcset support.
Comment #55
RainbowArrayThe browsers in question are all browsers out today. D8 is supporting browsers like IE11, so using no src on the img is something we need to ge able to do.
Firefox won't always have this behind a flag. That's a temporary thing.
Comment #56
webchickCool, thanks for answering!
Comment #57
attiks CreditAttribution: attiks commentedThis should be good to get committed, the remarks from dawehner are better handled in a separate issue, since this is not just about these newly added tests.
Comment #58
Jelle_SI'm guessing this will need a reroll because #2333395: Add sizes to template_preprocess_image has been committed.
Comment #61
Jelle_SRerolled patch
Comment #62
Jelle_SSince it's just a reroll...
Comment #63
webchickOk great! Committed and pushed to 8.x. Thanks!
Almost there. :)