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
The contextual_preprocess function makes plenty of assumptions on what is being put inside the template and what is being printed inside the template. This is easy to break and is something new for many themers.
The way this is implements doesn't really match the way we want the preprocess functions to be used in future where we might want to prevent preprocess functions from adding new variables to templates.
Proposed resolution
Try to convert contextual_preprocess function to #post_render. It would make contextual links less fragile since then what is printed inside the template wouldn't affect contextual links.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#6 | convert-2809675-6.patch | 3.08 KB | lauriii |
Comments
Comment #2
lauriiiFabianx proposed to "add an alter hook so that contextual links could instead of changing the variables in preprocess change the render array to add #post_render in the exact same way.
That would allow it continue to work for all cases, where a render array implements #theme.
We had discussed adding alter hooks before to be able to extend #pre_render and #post_render, but no real true use case for that.
This would be one and likely the reason preprocess was chosen for contextual links was due to no generic render array changing alter hook being available. It would likely run directly before the theme handler is called."
Comment #3
lauriiiComment #4
lauriiiComment #6
lauriiiThis is not #post_render but uses instead #theme_wrappers to wrap entities. This is just a proof of concept and only works for entities but I wanted to post this to get some feedback on the approach. I believe this approach should make the contextual links more robust compared to what we have currently.
Comment #17
larowlanAdding an extra wrapper will surely break things like flex layouts
And I don't think we can do that in a BC fashion.
Do we still want to pursue this?
Comment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedIf still a valid feature request will have to consider the BC as @larowlan mentioned. Closing for now as it's been a year. But feel free to reopen
Thanks!