Problem/Motivation
The themes #image_formatter
and #image_style
are both taking the image style name as argument. Then the image style object is loaded in the theme layer, in preprocess. That's a bad design because puts the loading and validating objects logic in the theme layer. Theme layer should not be in business of loading and validating. These are backend operations. The backend should be responsible of loading, validating and preparing the correct image style to be used by the theme.
Proposed resolution
- Deprecate the usage of
#image_style
theme variable 'style_name' in favour of a new 'style' that will hold the entire image style object. If the deprecated variable 'style_name' will get a non-empty value, that will take precedence in theme preprocess to assure a full BC. - Deprecate the usage of
#image_formatter
theme variable 'image_style' in favour of a new 'style' that will hold the entire image style object. If the deprecated 'image_style' will get a non-empty value, that will take precedence in preprocess to assure a full BC. - Make core use the new variables.
- In 9.0.x drop the deprecated variables. Open a followup for that.
Remaining tasks
Open a 9.0.x followup for removing deprecated variables.
User interface changes
None.
API changes
- New variable 'style' available to 'image_style' theme.
- New variable 'style' available to 'image_formatter' theme.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#25 | reroll_8-25.txt | 8.68 KB | pradhumanjain2311 |
#25 | 2589847-25.patch | 5.36 KB | pradhumanjain2311 |
#8 | 2589847-8.patch | 6.88 KB | mondrake |
Issue fork drupal-2589847
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
mondrakeYes! That's in line with what discussed in #2479487-85: ImageStyles can be deleted while having dependent configuration. and below. I suppose it's 8.1.x stuff, though?
Comment #5
claudiu.cristeaI would like to have some input from the theme team.
Comment #6
claudiu.cristeaComment #7
star-szrArchitecturally it does seem cleaner but maybe there's a use case here. I might have a clearer opinion once I see a patch, or even some before/after pseudo code.
Would the style name still be available to the theme layer if one wanted to add a theme suggestion based on the style name, for example? I guess you could always call ->getName() on the ImageStyle object?
Adding a somewhat related issue that wants to load image styles (by name) via Twig template to draw a parallel there.
Comment #8
mondrakeThis is the (my) idea.
@Cottser
Exactly, see the example in
template_preprocess_image_style
for passing the style name to the 'image' theme.Comment #9
claudiu.cristeaGreat! :)
Nice. I would add at the end of @todo a new phrase: "The image style name can be extracted from the 'style' variable
$variables['style']->getName()
". Not very sure about the grammar.I'm confused now about the scope of the entire issue. So, we pass an object to Twig template? How to use an object in a Twig template? Maybe it's possible (I'm ignorant with theming) but isn't this more complicated for a themer than before? I think a themer should receive only scalars and in some special circumstances sequences or associative arrays. I think we need somehow to extract everything that is usable in a template from the object and inject them as scalars into the Twig template. I see that new 'style_name' variable in image-style.html.twig. I like that and maybe we can do the same in image-formatter? Maybe along with all other valuable info embedded in the image style object?
A little bit confused abut this comment :)
Comment #10
star-szrI think the #2 change is so that you can still get the image style name for example. Because the new way would not pass the image style name. In a way this could maybe be documented stronger so it's not just optional, but that's just based on that snippet, been a while since I looked at the full patch (and on my phone now).
Comment #24
kim.pepperReviewed this as part of Bug Smash Initiative. As this is more about changing existing functionality, I'm reclassifying as a Task.
Comment #25
pradhumanjain2311 CreditAttribution: pradhumanjain2311 at OpenSense Labs for DrupalFit commentedPatch reroll for version 9.5.x. Needs review.
Still needs work for comment #9