Problem/Motivation
After template became the default for theme hooks in #2226207: Make 'template' the default output option for hook_theme() template_preprocess() and other non-hook-specific preprocess functions run even for theme hooks implemented as theme functions. Documentation and comments in the Theme Registry say this shouldn't be the case. The cause is all theme registry entries mistakenly getting a template key/value and the preprocess functions getting added based on the existence of the 'template' key.
Proposed resolution
Don't add a template entry for every theme hook in the registry. Then template_preprocess will not get added to the list of preprocess functions for these hooks.
Remaining tasks
Resolve any remaining issues with the attached patch.
Beta phase evaluation
Issue category | Bug because functionality different to documented intention |
---|---|
Issue priority | Normal |
Prioritized changes | The main goal of this issue is a bugfix. |
Disruption | Not disruptive, fixes unintended behavior. |
Comment | File | Size | Author |
---|---|---|---|
#25 | template_preprocess-2493989-25.patch | 3.47 KB | Antti J. Salminen |
#21 | 2493989_21.patch | 3.48 KB | slashrsm |
#18 | interdiff.txt | 1.49 KB | Antti J. Salminen |
#18 | template_preprocess-2493989-17.patch | 3.49 KB | Antti J. Salminen |
#16 | template_preprocess-2493989-16.patch | 2.73 KB | Antti J. Salminen |
Comments
Comment #1
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedComment #2
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedComment #3
lauriiiI don't understand how this would fix the bug?
Comment #4
lauriiiComment #5
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedIt's not visible in the patch but this if has an elseif that takes care of defaulting to 'template'.
The problem is that that the elseif is reached almost always. Only case where it won't be is when there is a theme function defined in hook_theme AND that theme function does not exist. So effectively 99.9% of the time it all amounts to "if there is no 'template' set a 'template'".
Comment #6
lauriiiComment #7
lauriiiComment #8
star-szrSuper duper minor and doesn't really apply here but &$variables :)
Looks good!
Comment #9
star-szrOnly one other thing:
This should probably have an inline comment about what it's testing…
Comment #10
lauriiiFixing!
Comment #11
lauriiiFixing more stuff!
Comment #16
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedLet's try with the initial patch and lauriii's tests.
Comment #17
star-szrAdding some feedback from IRC so it's here too.
Might be clearer for the elseif after this to instead do:
if (!isset($info['function']) && !isset($info['template'])) {
I think we should add in the theme_test module (or wherever) template_preprocess_theme_test_function_suggestions() to make sure that still works.
Because that's what didn't work with lauriii's approach and is still pretty important. We just don't want the template_preprocess() function itself running for theme functions.
Comment #18
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedSo this should test for the template_preprocess_hook as well, seems like a very good idea.
As for the elseif, I agree that clarity is key but isn't the if...elseif already pretty simple and arguably easier to read with just a single test per conditional?
Comment #19
slashrsm CreditAttribution: slashrsm at Examiner.com commentedFound this when playing with bootstrap which does some altering on theme registry, which eventually broke all theme hook that use functions.
Patch looks good to me. I agree if/elseif should be pretty clear and self-explanatory.
Thank you for fixing this. Great job!
Comment #20
slashrsm CreditAttribution: slashrsm at Examiner.com commentedMeh... I noticed something else.
Indentation seems to be a bit off here.
Comment #21
slashrsm CreditAttribution: slashrsm at Examiner.com commentedComment #22
marcingy CreditAttribution: marcingy at Examiner.com commentedI was discussing this issue with @slashrsm around bootstrap and patch looks good.
Comment #25
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedJust a reroll to make it apply again. Issue summary updates.
Comment #26
tim.plunkettComment #27
star-szr+1, thanks!
Comment #28
lauriii+1 for RTBC
Comment #29
catchCommitted/pushed to 8.0.x, thanks!