The drupal_render_cache_generate_placeholder() requests a specific unique token and is output as a 'token' attribute in the placeholder HTML. The problem I see with this is that all the usages in core also pass in the same token in $context['token'] so it gets embedded via the context array. This results in duplication because we're always doing drupal_render_cache_generate_placeholder($callback, $context, $context['token'])
and it duplicates the token value in the context and token attributes of the placeholder HTML.
I propose that drupal_render_cache_generate_placeholder() removes the 'token' argument and provides one by default by merging it into the $context array if not already present.
Comment | File | Size | Author |
---|---|---|---|
#9 | interdiff.txt | 693 bytes | Wim Leers |
#9 | 2275679-render-cache-token-unnecessary-9.patch | 12.96 KB | Wim Leers |
Comments
Comment #1
Dave ReidComment #2
Dave ReidConfirmed that removing drupal_render_cache_generate_token() works just fine and makes all the code that uses render cache placeholders a bit simpler since they're all doing exactly the same thing.
Comment #3
Wim LeersYES! Thanks for creating this issue!
This is a consequence of changes made in #2099131: Use #pre_render pattern for entity render caching, we failed to clean it up there.
So +1 to:
The only thing I'm not sure of is whether we want
or:
or even:
I think it's useful to have the callback serialized in there for debugging purposes, but the entire context… that's less useful.
Comment #4
Dave ReidYeah I will agree having the callback in the token was more helpful at times than having the context in there. I debated going down to just the token attribute, but let's leave callback in there.
Comment #6
Dave ReidFixed test failures.
Comment #7
Dave ReidSigh, I accidentally removed the callback attribute from the placeholder.
Comment #9
Wim Leers#7 is perfect, except for one stupid typo. So fixing that typo and RTBC'ing at the same time.
Thanks a lot, Dave! :)
Comment #10
Dave ReidYes, thanks for fixing my inability to spell uniquely. Sigh.
Comment #11
catchCommitted/pushed to 8.x, thanks!
Comment #14
Fabianx CreditAttribution: Fabianx commentedThe original change notice for this, that I can't even seem to find atm. needs an update. It has the $context token example wrong.
Also the documentation https://api.drupal.org/api/drupal/core!includes!common.inc/function/drup... is wrong and still speaks of drupal_pre_render_render_cache_placeholder.
And another bug:
else the whole setup in the beginning is in vain ...
Edit: Not a bug, just a check that the $callback is callable.
Comment #18
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThis functionality has been replaced with normal placeholders => closing again.