Problem/Motivation
It's difficult to extend the responsive-image.html.twig template in small ways, because every implementation of the template duplicates everything, rather than extending. But it is particularly difficult because the majority of the logic still happens in a preprocess function.
Proposed resolution
Remove template_preprocess_responsive_image(), move its logic into the Twig template.
But keep BC for the Stable & Classy themes, so duplicate that preprocess function to stable.theme.
Remaining tasks
- First do these 3 soft-blockers:
- #2423743: streamline responsive_image_build_source_attributes()
- #2421317: Do #attributes/$variables['attributes'] to go the <picture> or the fallback <img>?
- #2701255: responsive_image_preprocess_responsive_image() and responsive-image.html.twig never render width and height variables despite claiming otherwise
- Then start pushing this forward, and consider adding a
image_style_url($image_url, $image_style)Twig function (see #3)
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | remove_template_preprocess_responsive_image-2701667-5.patch | 10.85 KB | wim leers |
Comments
Comment #2
wim leersStrongly related:
All 3 of those issues simplify/remove WTFs in the preprocess function, and would therefore help make this issue happen.
Comment #3
wim leersNote that for this particular issue (unlike #2694179: Remove template_preprocess_image() and #2699635: Remove template_preprocess_form_element_label() for example), it probably makes sense to define additional Twig functions.
For example: besides the
file_url()andurl()Twig functions, also havingimage_style_url($image_url, $image_style)would be very valuable. It may even be a necessity to make this issue happen. But it would also be valuable to front-end developers in other templates.Comment #4
wim leersUpdated IS per #2 and #3.
Comment #5
wim leersHere's what we can do for now.
Comment #18
catch