Proposed commit message:
Issue #939462 by lauriii, Antti J. Salminen, NROTC_Webmaster, mbrett5062, tim.plunkett, tostinni, rteijeiro, dvessel, barraponto, theapi, joelpittet, cilefen, tuutti, drzraf, Fabianx, markcarver, xjm, catch, jenlampton, sun, effulgentsia, Cottser, davidhernandez, kscheirer, andypost, akalata, rooby, hass, fubhy, jhodgdon, lemunet, gleroux02, mike stewart, kevinquillen, MXT, mlncn, becw, PavanL, chriscalip: Specific preprocess functions for theme hook suggestions are not invoked
General summary
- This is not considered a beta blocker or critical issue for D8.
- While patches exist in this thread for D7 (and may work for you), official fix will be to D8 first -- please do not switch issue metadata until we are ready to start the D7 backport.
Problem/Motivation
When you have a template suggestion available and are using that template, preprocess functions following naming conventions provided via hook_theme_suggestions_HOOK() are not being recognized, for example:
MYTHEME_preprocess_node__article()
MYTHEME_preprocess_block__search_form_block()
MYMODULE_preprocess_page__front()
MYMODULE_item_list__search_results()
etc.
Proposed resolution
Add a post-process step to the theme registry build to look for these types of preprocess functions and add them to the theme registry.
Remaining tasks
Patch needs review.
User interface changes
N/A
API changes
Removes the global drupal_group_functions_by_prefix() (moves it to a class to make things testable) which was added May 13, 2015: #2339447: Improve theme registry build performance by 85%
Beta phase evaluation
Issue category | Bug, there was similar functionality to this in Drupal 6, or at least in Views |
---|---|
Issue priority | Major because it represents a big improvement to themer/developer experience. |
Disruption | Little to no disruption, just an addition that core and contrib can choose to use or not use. |
Drupal 7
Drupal 7 issue: #2563445: Specific preprocess functions for theme hook suggestions are not invoked
Related Issues
- #2229355: Field template suggestions are colliding
- #2307103: Follow-up: remove explicit comment field theme hook suggestion implementation via #1962846: Use field instance name for header of comment list, drop comment-wrapper template
- #2231853: Rename maintenance-page template into page--maintenance + install-page into page--maintenance--install is working around this issue
- this issue is blocking #1885714: Remove theme_install_page()
- also appears to be blocking #2231853: Rename maintenance-page template into page--maintenance + install-page into page--maintenance--install?
Comment | File | Size | Author |
---|---|---|---|
#359 | interdiff.txt | 2.94 KB | lauriii |
#359 | specific_preprocess-939462-359.patch | 23.53 KB | lauriii |
#355 | drupal_939462_355.patch | 23.05 KB | Xano |
#355 | interdiff.txt | 1.2 KB | Xano |
Comments
Comment #1
sense-designTry this:
Comment #2
gleroux02 CreditAttribution: gleroux02 commentedYou are right that the code that you provided will allow the specific views preprocess function to get picked up, but I should not have to declare each preprocess function in my theme by adding it to a hook_theme function. It should just get picked up if that tpl is in the theme.
Comment #3
becw CreditAttribution: becw commentedThis seems to be a core
theme()
behavior: if the 'base hook' property is set for a theme registry item,theme()
will use the 'preprocess functions' and 'process functions' from the 'base hook' theme registry item. This means that currently, preprocess functions for the'views_view__test_preprocess'
theme registry item will always get ignored in favor of the preprocess functions on the'views_view'
theme registry item, since$theme_registry['views_view__test_preprocess']['base hook']
is set to 'views_view'.gleroux02, I believe this is a change in behavior from using Views on Drupal 6? The 'base hook' theme registry property seems to be new in Drupal 7, and its presence is not documented in the hook_theme() docs (http://api.drupal.org/api/function/hook_theme/7). Inline documentation in
theme()
indicates that the original theme registry item name is retained in$variables['theme_hook_suggestion']
, so if the core behavior is correct, then maybetemplate_preprocess_views_view()
could check there and execute any additional preprocess functions itself...Comment #4
becw CreditAttribution: becw commentedThis issue is related to commit 344200 and #241570: Theme preprocess functions do not get retained when using patterns.
Comment #5
MXTTracking. See my comment here: http://drupal.org/node/241570#comment-3679436
Comment #6
effulgentsia CreditAttribution: effulgentsia commentedI'm moving this issue to the core queue, in order to close out #241570: Theme preprocess functions do not get retained when using patterns. That other issue initially dealt with a related, but different problem, which was that hook_preprocess_views_view() wasn't called when views-view--page-1.tpl.php was being used. That issue was fixed for D6 in #241570-6: Theme preprocess functions do not get retained when using patterns and for D7 in #241570-50: Theme preprocess functions do not get retained when using patterns. The D6 solution made it so that both hook_preprocess_views_view() and hook_preprocess_views_view__page_1() would be called. The D7 solution intentionally made it so that only hook_preprocess_views_view() would be called. There has been further discussion in that issue requesting that hook_preprocess_views_view__page_1() be added to the D7 theme system, so that D7 doesn't represent a regression to D6 in this regard. I'd like that discussion to continue in this issue, so that new people joining the discussion don't need to read that issue's history, and can just focus on this particular question.
Here are some things I don't like about the way in which D6 implements suggestion-specific preprocess functions:
And, you need mymodule_theme() to run AFTER views_theme(), which probably means you need to set the system weight of mymodule to 1 or higher.
'views-view--taxonomy-term-leaf.tpl.php' and 'views-view--taxonomy-term-leaf--page.tpl.php' files. When the 'views-view--taxonomy-term-leaf--page.tpl.php' file is used, I would expect mytheme_preprocess_views_view__taxonomy_term_leaf() and mytheme_preprocess_views_view__taxonomy_term_leaf__page() to both be called, but they're not. Only mytheme_preprocess_views_view__taxonomy_term_leaf__page() is.
IMO, the above WTFs make suggestion-specific preprocess functions more trouble than they're worth. To me, the following construct is preferable:
Although I realize that the above isn't as syntactically attractive as a targeted function name, in D7, this construct works without the prior WTFs:
Note, what I say above is not fully true yet, but requires #956520-16: Available theme hook suggestions are only exposed when there are preprocess functions defined to be made true. But that's a totally straightforward patch that needs to be committed to core anyway, and I'm confident will be pretty soon (maybe not before RC, but soon).
So, my recommendation is to mark this issue "won't fix" or kick it to D8, and to require the less attractive, but more robust, pattern to be used for suggestion-specific preprocessing in D7. Alternatively, a contrib module like ctools can implement hook_theme_registry_alter() to make suggestion-specific preprocess functions work in D7 (with all the limitations they have in D6, or maybe even fixing some of them).
But, that's my recommendation only. Please share your thoughts. If my arguments for why suggestion-specific preprocess functions are undesirable in D7 core aren't persuasive, and if the community really wants this D6->D7 regression fixed, I'll support a D7 core patch to fix it.
I'm marking this issue major, rather than critical, because this is something that can be done after RC, and even in a 7.1 release.
Comment #7
sunQuite a summary :-D
My issue (elsewhere) actually was that this doesn't work:
According to Jacine, this seems to work for themes, and possibly also for templates, but not for preprocess theme functions of modules.
Comment #8
effulgentsia CreditAttribution: effulgentsia commentedYep, as per #6 (limitations 1-5), the equivalent of #7 doesn't work in D6 either. I'd love to see it fixed properly in D8. Now that we have a module_implements() cache, I think in D8 we can merge the way we do drupal_alter() with the way we do preprocess functions, simplifying the API and the theme registry building process, and reducing the size of the theme registry, shaving a few ms from each page request. But I'm not sure it makes sense as D7 material.
Comment #9
helior CreditAttribution: helior commented+1
Comment #10
mlncn CreditAttribution: mlncn commentedSubscribing, asking if this can be fixed in Drupal 7 (because it would be lovely), but looking to do it right in D8 in any case. Frankly i think the examplemodule_preprocess_links__node() function should not only be called but override the template_preprocess_links() function, as you could easily call the general function from within your specific preprocess function if you want it.
Comment #11
droplet CreditAttribution: droplet commentedSubscribing
Comment #12
fubhy CreditAttribution: fubhy commentedUntil this is "fixed" just do the following:
Comment #13
mlncn CreditAttribution: mlncn commentedSubscribing and hoping someone can get to benchmarks on #956520: Available theme hook suggestions are only exposed when there are preprocess functions defined soon and then we can revisit this issue.
Comment #14
tinefin CreditAttribution: tinefin commentedSubscribing
Comment #15
temosayin CreditAttribution: temosayin commentedsubscribing also
Comment #16
lemunet CreditAttribution: lemunet commentedBefore in D6 when you had the tpl file like
views-view-fields--VIEWNAME--block-1.tpl.php
the preprocess function was properly called.
the same thing for D7 is NOT working anymore...
if you do something like:
it works fine like the above example,
but it DOES NOT work for specific view + display, like the example bellow:
any thoughts out there?
My temporary solution for D7 at this point:
Comment #17
carn1x CreditAttribution: carn1x commentedsubscribing
EDIT: I followed the instructions in comments #12 and #16 however it seems that I'm not able to get them to fire either from my base theme or my sub theme? Did you guys have to do anything special in the first place to get theme hooks to be called?
I've opened a separate issue for this problem as I realise it's probably off topic, but I was hoping you might have already trodden this path: #1160268: subtheme_preprocess_page not getting called
EDIT 2: Ok seems I've gotten around this problem without knowing how, thanks to #12 / #16 your advice is now working :)
Comment #18
lemunet CreditAttribution: lemunet commentedTo carn1x...
This was my temporary solution I still don't know why on D6 the preprocess functions worked without the above code... and that's why I posted it here... I still want a proper explanation for that?
Thanks...
Comment #19
dvessel CreditAttribution: dvessel commentedAh! I was looking for this issue. I posted in the wrong place but this patch will fix it.
http://drupal.org/node/956520#comment-4478448
There's a bit more info starting from that comment.
Comment #21
dvessel CreditAttribution: dvessel commentedfrom effulgentsia overview #6:
The patch fixes this.
Also fixed. You don't even need the 'views-view--page-1.tpl.php file to exist at all. If the variable process function implements it, it will auto register the hook and inherit all the base elements.
This should also be fixed but I haven't tested this.
We have to draw the line somewhere and as I was writing the patch, there was an note in drupal_find_theme_functions() to "keep things simple". I could have written the patch to do what your expecting and I was considering it but it is most likely overkill.
You meanmytheme_preprocess_node__story
? That would depend on howtheme()
called and it's outside the scope of the theme function.EDIT: Actually, the same problems exists even with the change from 'template_file_suggestions' to 'theme_hook_suggestions'. Although the patch doesn't address this, I did find a workaround in a patch to a theme I've been working on: #1179656: Consistent availability of variable processor, file includes and auto registration for hook__suggestions. see point #3. I can update the patch to fix it in core but I think an entirely different approach in core should be made for 8. 'theme_hook_suggestions' being set from preprocess works against it.
Comment #22
dvessel CreditAttribution: dvessel commentedLets try that again. That was an old patch.
Comment #24
dvessel CreditAttribution: dvessel commentedWhy is the test server getting a 404 on the patch?
Comment #25
dvessel CreditAttribution: dvessel commentedEh, hidden space in the file name.
Comment #26
dvessel CreditAttribution: dvessel commentedComment #28
dvessel CreditAttribution: dvessel commentedNot sure what the deal is. It was tested two days ago and it passed. Passes locally also.
Fails on comment block but theme_comment_block isn't all that special.
Comment #29
dvessel CreditAttribution: dvessel commented#25: specific_preprocess_hook_suggestions_939462_25.patch queued for re-testing.
Comment #30
marcp CreditAttribution: marcp commentedAnyone other than dvessel get a chance to test out the latest D7 patch yet?
Comment #31
dvessel CreditAttribution: dvessel commentedI'll try again by creating a patch for 8 then back port it to 7. Might get more attention.
Comment #32
MXTI've just applied the patch in #25 on my D7.2 installation and I can confirm that now my
is now correctly picked up: YEAHHHH!!!
I was waiting for that for a long time:
Thank you very much!
Comment #33
JGO CreditAttribution: JGO commentedSame here, fixed the prob. Hope it gets into the code soon :)
Comment #34
chriscalip CreditAttribution: chriscalip commentedapplied in D7.4 installation; confirmed that its working.
Here's are some numbers:
Here are the results:
example_chris_preprocess_item_list
0.31776300 1309472124
item_list__first
example_chris_preprocess_item_list__first
0.31799800 1309472124
item_list__first
Comment #35
chriscalip CreditAttribution: chriscalip commentedI think 3 people is enough for RTBC; I realize that this is theme.inc we are talking about, let me know if brief glances by 3 people is not enough for an RTBC, and what could we do to make this an RTBC. xhprof profiler benchmarking needed? I'll provide if asked.
Comment #36
catchYeah this one really needs so profiling, leaving at CNR rather than CNW since it may still apply to D8.
The main change here is theme rebuilds, so you would need to profile a page that is building the theme registry cache. xhprof should show the difference both in CPU and memory for that if it's done before/after. Main thing to watch out for the APC or other opcode cache if you're running that - should either be consistently warm or consistently cold (or just disabled).
As well as this, I can see a call to get_defined_functions() then array operations on that, can't see that doing anything other than increasing the memory requirements here but will need testing. I've been thinking about trying to move away from including files altogether and instead scan them with regexp at #1188084: Try to avoid loading every specified include file during theme registry rebuilds. although this has no code yet so shouldn't hold the patch up in itself.
Apart from that there's also an issue at #519940: Performance: optimize building theme registry by using get_defined_functions() instead of function_exists() using get_defined_functions() elsewhere in the theme registry rebuild process, not sure if that is applicable at all here (maybe the function_exists() calls that aren't removed?).
And there are no tests added in this patch but this ought to be testable I think.
Comment #37
jox CreditAttribution: jox commentedSubscribing.
Comment #38
rooby CreditAttribution: rooby commentedSubscribing
Comment #39
rfabbri CreditAttribution: rfabbri commented#25 breaks drupal for me...
It seems that doing a git apply -v specific_preprocess_hook_suggestions_939462_25.patch on the root of drupal doesn't patch correctly the theme.inc file... (Using Git 1.7.6-preview20110708)
The warning I got after reverting to the original, seems to indicate an include path problem...
Warning: include(C:\www\apache\htdocs\mysite.com/page.tpl.php) [function.include]: failed to open stream: No such file or directory in theme_render_template() (line 1276 of C:\www\apache\htdocs\mysite.com\includes\theme.inc).
Warning: include() [function.include]: Failed opening 'C:\www\apache\htdocs\mysite.com/page.tpl.php' for inclusion (include_path='.;C:\php5\pear') in theme_render_template() (line 1276 of C:\www\apache\htdocs\mysite.com\includes\theme.inc).
I got lots of the same kind of warning for the block.tpl.php, toolbar.tpl.php, html.tpl.php file (same invalid file structure).
I presume the patch has a problem ?
Comment #40
xjmTagging issues not yet using summary template.
Comment #41
Agileware CreditAttribution: Agileware commentedSub
Comment #42
jherencia CreditAttribution: jherencia commentedComment #43
catchTagging for backport.
Comment #44
aroq CreditAttribution: aroq commentedSubscribing.
Comment #45
jpargana CreditAttribution: jpargana commentedWith the new Drupal version update (7.9), is needed a new patch to correct this problem.
Comment #46
xjmThis will need to be rerolled now.
Comment #47
jenlamptontagging for learnability.
Comment #48
drzraf CreditAttribution: drzraf commented(rerolled #25 for D7)
Assumption n°3 of comment 21 confirmed is also confirmed:
SUBtheme_preprocess_views_view__VIEWNAME_DISPLAYID(&$vars)
is fired(without the template file)
This patch (almost) made my day, but ... I'm getting a bunch of notices:
Notice : Indirect modification of overloaded element of ThemeRegistry has no effect dans theme() (line 1008 in /var/www/drupal/includes/theme.inc).
(the line is
unset($hooks[$hook]['includes'])
)Comment #49
theapi CreditAttribution: theapi commented#25: specific_preprocess_hook_suggestions_939462_25.patch queued for re-testing.
Comment #51
xjmThe patch does not apply. It needs to be created with git. :)
Comment #52
theapi CreditAttribution: theapi commentedGit version of the patch at #25
Comment #53
xjmWe need to create a patch for D8 first, and then profile it as catch says above. (When an issue is fixed, the fix is usually backported to D7 around the same time.)
The patch above might apply to D8 from within the
core/
directory so I'd suggest trying that in order to create a D8 patch.Comment #54
drzraf CreditAttribution: drzraf commentedI don't have a D8 to port this patch to,
but can someone elaborate on these ThemeRegistry warnings ?
Comment #55
xjmYou can get D8 from git using these instructions:
http://drupal.org/project/drupal/git-instructions
Comment #56
catchIt looks like _theme_post_process_registry() is acting directly on the cached ThemeRegistry object, whereas it should be acting on the raw theme registry array which is created during the rebuild. I didn't look beyond this but hopefully that'll help you track it down.
Comment #57
theapi CreditAttribution: theapi commentedHere's a D8 Git version of the patch. I've commented out the line
unset($hooks[$hook]['includes']);
as it did nothing except cause errors. The functionality it represents may still be required though. I'm simply creating the patch for D8 to help the effort along. Sadly I believe it will fail testing.
Comment #58
jenlamptonChanging status for testbot.
Comment #60
xjmThe patch in #57 appears to be either old or against 7.x; it is missing the
core/
directory.Comment #61
jschrab CreditAttribution: jschrab commentedI've been using this technique with great success. However, I would like to point out that the pass-by-reference forcing in...
...can cause "Call-time pass-by-reference has been deprecated..." errors in newer versions of PHP. Since your "mytheme_preprocess_views_view_list__VIEWNAME__DISPLAY" function makes a pass-by-reference declaration in the function parameter definition, you're still fine and get the behavior you want with out the PHP warning.
So it should be...
Comment #62
tim.plunkettReroll.
This fixes my problem for D7, didn't try it on D8.
Comment #63
tim.plunkettTo clarify, my problem was what sun described in #7.
Comment #64
xjmThanks for the reroll.
Code style review:
Looks like these comments are wrapping a bit early.
This change is superfluous to the patch.
The word "This" is not needed here; it should just begin "Completes..." Reference: http://drupal.org/node/1354#functions
Also, it would be better to have a comma after "registry."
This line is one character too long; we need to wrap it a word earlier.
Also one character too long.
We shouldn't have commented-out code.
Also, we still need a test here as well, and that profiling. Thanks!
Comment #65
xjmOh, tagging novice for the task of cleaning up the code style issues in #64.
Comment #66
mike stewart CreditAttribution: mike stewart commentedworking on in the Long Beach Contribute meetup tonight: http://groups.drupal.org/node/211453
(we're in IRC in #drupal-la and #drupal)
Comment #67
bvanmeurs CreditAttribution: bvanmeurs commentedJust encountered this issue. Seems to take too long to get this fixed imho. Subscribing.
Comment #68
xjm@bvanmeurs, you can help speed along the process by any of the following:
Thanks!
Edit @mike stewart -- I saw the complaint but not your comment. That's awesome; thank you so much!
Comment #69
mike stewart CreditAttribution: mike stewart commentedarg! new laptop ... spent too much of the meeting last night just getting setup. finally a working environment (late) to discover that the patch would no longer cleanly apply.
error: patch failed: core/includes/theme.inc:1008
need to do a diff in D8 commits on that file to see whats new.
Also #62 @tim.plunkett's comment wasn't clear to me. He said this fixes his problem in D7 but not D8 -- but the patch is clearly a D8 patch, so I wanted to be sure thats where the re-roll belongs? (I assume yes -- but clarification would be nice).
I am busy for the next few hours, but hope to get back to this later today... but didn't want to prevent anyone else from working on, so I've unassigned. If no one else picks up ... I'll be back :-]
Comment #70
tim.plunkett@mike stewart, I was saying I'd only tested it on D7, not that it didn't work on D8.
Comment #71
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedIs this related to http://drupal.org/node/1430300? Can anyone see if this is still required? I have attached the patch from #62 with comments from xjm in #64.
Additionally I can try to make a test for it if someone can provide basic instructions on what is required. If not I'll hand this back over to mike for the testing.
Comment #73
effulgentsia CreditAttribution: effulgentsia commentedThis isn't related to #1430300: Preprocess functions in an include file fail to get called when the theme implements a suggestion override, but you can extend the test from that issue which is now in both 8 and 7.
If in test_theme/template.php, you add a
test_theme_preprocess_theme_test__suggestion()
function that adds a variable, and changetest_theme_theme_test__suggestion()
to include that variable in its output, and include that in the assetion inThemeUnitTest::testPreprocessForSuggestions()
, that would test what's being fixed in this issue.Comment #74
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedHere is the patch for the test. It fails locally with or without the patch. Let me know if I made it wrong though. I've still new to testing.
The testbot probably kept failing because of the line unset($hooks[$hook]['includes']); which causes
Notice: Indirect modification of overloaded element of ThemeRegistry has no effect in theme() (line 1068 of /d8/core/includes/theme.inc).
Comment #76
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedLets try again.
Comment #77
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedComment #78
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedI'm not sure what happened with the last one but hopefully this one will finally apply but fail with the test. @effulgentsia Please let me know if I misunderstood what you were looking for in the test.
Comment #79
xjmThe testbot queue is quite backed up ATM:
http://qa.drupal.org/pifr/queued
So TBH I'd give it at least a day.
Comment #81
tim.plunkettThese were the lines added in #1430300: Preprocess functions in an include file fail to get called when the theme implements a suggestion override, are you sure they should be removed?
Comment #82
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedI'm not sure what the right answer is here. It probably shouldn't be taken out but since it is a nested if statement I don't know of a good way to leave it in while maintaining what the original patch in #62 did. If you let me know the proper way to handle this I can make a new patch that will apply and accomplish the goal.
Comment #83
gitesh.koli CreditAttribution: gitesh.koli commented#25: specific_preprocess_hook_suggestions_939462_25.patch queued for re-testing.
Comment #84
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedtim.plunkett,
This one still fails, but I added the code back in which fixed one of the errors.
Comment #86
barraponto CreditAttribution: barraponto commentedissues:
Comment #88
barraponto CreditAttribution: barraponto commentedYeah, it actually broke installation. I've patched the patch to revert some changes.
Comment #90
tim.plunkettI'm going to try to revisit this soon.
Comment #91
tim.plunkettOh yeah I tried and failed hard. No idea.
Comment #92
tim.plunkettHere's a test that proves this is broken.
The idea is that if you call a theme function with a suggestion, the preprocess for the suggestion should run even if there is only a default theme function.
Comment #94
tim.plunkettBecause I got confused a couple times with all the theme_test_test_theme_theme stuff, here is a simplified example of what is wrong here:
The test in #92 asserts that the result of
foo_page()
is 'bar' and not 'foo'.Is this correct?
Comment #95
fubhy CreditAttribution: fubhy commentedYes, that should be the expected behavior / result.
Comment #96
tim.plunkettGlad to hear it. Rerolled for PSR-0.
Comment #98
effulgentsia CreditAttribution: effulgentsia commentedI haven't followed all the latest work here, but I think #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() might be a good approach to solving this. The patch there still needs refinement, but linking to it here for anyone interested.
Comment #99
effulgentsia CreditAttribution: effulgentsia commentedThis will need to get solved for #1804614: [meta] Consolidate theme functions and properly use theme suggestions in core, so tagging accordingly. I'm tempted to mark this a dupe of #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter(), but not doing so yet, cause it's not yet clear whether there's consensus on that being the best approach, and there's work that's been done on this issue that I haven't reviewed yet, but still want to.
Comment #100
brunogoossens CreditAttribution: brunogoossens commentedMy solution for this problem is merging the preprocess functions and deleting the 'base hook'.
This solution worked for me:
Comment #101
kscheirerTests in #96 succesfully fail. I think this test is RTBC, but I'll check in #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() and see is that resolves the test.
Comment #102
kscheirer#96: drupal-939462-96.patch queued for re-testing.
Comment #103
tim.plunkettThe tests fail, yes. Because we have no fix yet :)
Comment #104
catchIf the test in #96 fails, that's great, but we can't commit it to 8.x without an accompanying fix..
Comment #106
Fabianx CreditAttribution: Fabianx commentedTagging with Twig so I can find this again ...
Comment #107
Fabianx CreditAttribution: Fabianx commentedMarked #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() as duplicate of this issue.
Comment #108
sunoh, wow, scrolling back to #8 was really worth it — @effulgentsia mentioned:
This:
would apparently be in line with my findings and workaround/changes in #782672-16: Loosen the coupling between the user module and the installer/maintenance theme (though the problem space over there is slightly different)
The tricky part would be to get
drupal_alter()
working for the special hook naming pattern of theme [pre]processors, which isn't the regularhook_fixed_DYNAMIC()
, but instead,template_preprocess_DYNAMIC()
plushook_preprocess_DYNAMIC()
, and all without_alter
suffix (although we could decide to change that).Comment #109
Fabianx CreditAttribution: Fabianx commentedAnd yet another potential duplicate (arrrgh), but that one has a patch:
#956520-30: Available theme hook suggestions are only exposed when there are preprocess functions defined
Edit:
Marked as duplicate as the patch was moved over here and the last working version is in #62 in this issue.
Comment #110
mitchell CreditAttribution: mitchell commented#62 works for D7, #96 is the accompanying D7 test (which also works), and both need to be ported to D8. Is that right?
Side note: This is a blocker for #1647978: Entity API needs a 1.0 release as part of the Drupal.org D7 Upgrade Initiative.
Comment #111
catchThere's a patch on #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() that claims to work as well. I thought #96 was an 8.x test no?
#1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() seemed reasonable to me, so getting that patch working with the test from #96 would be good. If #62 is still in the running then the same thing with that for comparison.
Moving to CNW, 'to be ported' is generally for things that have been committed already.
Comment #112
jenlamptonChanging title to more closely match solution than original problem
Comment #113
Fabianx CreditAttribution: Fabianx commentedAdded some more problem into the title, this is still a bug and not a feature to be introduced.
Comment #114
kscheirer#96 is indeed a D8 test.
Comment #115
Fabianx CreditAttribution: Fabianx commentedSo for now someone needs to combine the test at #96 with a port of the patch at #62.
Or re-start with the test in #96 and a drupal_alter approach ... (which I personally find cleaner)
Comment #116
tostinni CreditAttribution: tostinni commentedHere is the port of #62 merged with the #96 test.
It's my first reroll for D8 so I quadruple checked everything and hope I haven't missed anything.
I used Drupal ladder lesson on re-roll patch and some
git log
to find the commit where #62 patch applied.Regarding the
drupal_alter()
, I'd rather let this for more experienced developers.Comment #118
tostinni CreditAttribution: tostinni commented#116: drupal-939462-116.patch queued for re-testing.
Comment #120
tostinni CreditAttribution: tostinni commentedI'm not sure why my patch is failing the tests, the installation went smoothly on my server.
Any suggestion ?
Comment #121
c4rl CreditAttribution: c4rl commented#116: drupal-939462-116.patch queued for re-testing.
Comment #123
tostinni CreditAttribution: tostinni commentedNew patch that applies to HEAD.
Comment #125
tostinni CreditAttribution: tostinni commentedPushing the patch without the tests.
Comment #127
kscheirerSeems like it's failing on
Which sounds more like a testbot problem than a patch problem.
Comment #128
tostinni CreditAttribution: tostinni commentedOk I've been able to reproduce this, WSOD on the install page, some theme function may have change too much during this time, I'll have another look at it on Sunday.
Comment #129
tostinni CreditAttribution: tostinni commentedNew try, a problem with the patch during maintenance mode was causing the WSOD. I modified this in the
theme()
function:if (isset($info['template'])) {
by
if (isset($info['template']) && !defined('MAINTENANCE_MODE')) {
Comment #131
tostinni CreditAttribution: tostinni commentedIncorrect patch in #129, sent corrected version.
Comment #133
tostinni CreditAttribution: tostinni commentedLast attempt for me.
Comment #135
mbrett5062 CreditAttribution: mbrett5062 commentedOK have rerolled and revised some things to get some of the test failures out. I found the following:
1.
$template_candidates = array($info['template'], str_replace($info['theme path'] . '/templates/', '', $info['template']));
This made the path for Bartik templates wrong. Revised '/templates/' to '/' on line #1314 in patched file.
2.
'theme_hook_original' => $original_hook,
This returned render array errors all over the place. So changed to '#theme_hook_original' and they are gone.
Still lots of errors, but hoping less then before, and maybe I can help get those down.
Of course my changes may be in error themselves.
If anyone with more experience would like to jump in here, please feel free.
And sorry, no interdiff as I did not realize I needed to create it before the patch.
Comment #136
mbrett5062 CreditAttribution: mbrett5062 commentedActually I can create an interdiff, just difficult to know which patch to make it to.
I too patch in #84 and #133 and made a cross patch of them. Mostly followed #84, which is very similar to #133.
Anyway here is interdiff to #133.
Comment #138
mbrett5062 CreditAttribution: mbrett5062 commentedOK that did not work, still something definitely wrong with paths being called.
For modules the path is repeated from 'core'.
For themes the path is repeated from 'core' and an extra 'templates' directory tacked on the end.
Also not picking up 'twig' templates when they are present.
Will investigate all path's in the code, see if I can track this down.
If anyone has more knowledge/idea of what is wrong here, please feel free to chime in.
Comment #139
mbrett5062 CreditAttribution: mbrett5062 commentedOK found out why the file path was being repeated
e.g. include(C:\xampp\htdocs\drupal8/core/themes/seven/templates/core/themes/seven/templates/templates/page.tpl.php)
Still can not get rid of second /templates/ at the end. If I remove it from here
Then it also gets removed from system.module calls in .include files templates.
Causing even more errors.
Any help or insight would be appreciated.
Hope I have not introduced a whole bunch more of errors.
Comment #141
mbrett5062 CreditAttribution: mbrett5062 commentedhhmmm
OK lets look at that again.
Comment #142
mbrett5062 CreditAttribution: mbrett5062 commentedOK was a little overzealous with my deletions, added back in part of previous change.
Should be able to install site for tests now.
Comment #144
mbrett5062 CreditAttribution: mbrett5062 commentedI have looked at this over and over. Seem to be chasing my tail around the same problems. Unable to solve this myself (Not enough experience), however I hope my observations below will help someone solve this.
With patch #142 applied the following occurs.
1) On lines #484-#487 of theme.inc the following code "allows system.module to declare theme functions on behalf of core .include files".
However it also adds "/templates/" a second time to the end of theme paths, so theme templates are not found.
If you remove it however, then system module templates are not found.
It seems that somewhere else in core, the theme path that gets passed to "$themed_path" has "/templates/" already declared.
This is one of the biggest show stoppers and may be hiding many other issues.
2) Around lines #512-#519 code was introduced to enable finding the best theme engine for the template (with the introduction of twig engine). However this included code already present to render the output using the template file around lines #1152-#1156.
I am not sure if that is required twice or not, but I did find that it introduced a problem with paths for template files.
If the following:
was removed altogether from both places, then the path for template files was not repeated.
include(C:\xampp\htdocs\drupal8/core/themes/seven/templates/core/themes/seven/templates/templates/page.tpl.php)
became
include(C:\xampp\htdocs\drupal8/core/themes/seven/templates/templates/page.tpl.php)
however, this only worked on already installed site. If you tried a new install with this in place, you got a WSOD for install page.
Re-introduce in only one place, and the double path was also re-introduced, so it is needed for install, but creates incorrect paths otherwise.
As you can see, a lot of circular path issues here.
I am sure there is probably an easy fix for all this, but it is beyond my experience level to find the solution.
Therefore, I will give this up so someone else can work on this.
Hope I have not wasted too much time.
Comment #145
mbrett5062 CreditAttribution: mbrett5062 commentedTaking this on again. Could not leave it alone.
Think I may have solved all the path issues at least. Basically did less messing with the existing code. Of course this may mean the issue does not get solved, but at least have a firmer footing for moving on with this.
Lets see what test bot thinks.
Comment #146
mbrett5062 CreditAttribution: mbrett5062 commentedOopps here bot.
Comment #148
mbrett5062 CreditAttribution: mbrett5062 commentedOK that's much better. Seems my change from 'theme_hook_original' to '#theme_hook_original' was either in error or I did not carry it through to later in the code when it is called. Testing locally to see what the fix is.
Comment #149
mbrett5062 CreditAttribution: mbrett5062 commentedOK think I have fixed the last issue of 'theme_hook_original' lets see what else comes up.
Comment #151
barraponto CreditAttribution: barraponto commented2 fails! We're getting close! Lots of love!
Comment #152
mbrett5062 CreditAttribution: mbrett5062 commentedFinally I think I have fixed the remaining 2 issues, at first I thought the problem was that we have not actually fixed the main issue and the tests were showing this. But having gone over and over the tests, I think there were some issues with our tests themselves. This patch fixes that as far as I can tell.
Of course, I may be completely wrong and have just massaged the tests to pass, without addressing the real issue.
So please, someone with more experience then me, look this over and make sure I am not working around the tests just to get things green.
I really am a novice, so please assume nothing :-)
Anyway here goes, lets see what the bot says anyway.
Comment #154
mbrett5062 CreditAttribution: mbrett5062 commentedOoppps there's a typo for you, lets try that again.
Comment #155
mbrett5062 CreditAttribution: mbrett5062 commentedOK getting over excited here :P. Lets try that with the bot.
Comment #156
mbrett5062 CreditAttribution: mbrett5062 commentedRight, that's it for me :-)
Next step is for someone with far more experience to review this and manually test if we have actually solved the issue and I have not just bent the patch to get green test results.
Unassigned from myself, as if this is not actually fixing the issue, then I have no clue how to make it work.
Good luck.
Comment #157
tim.plunkettWow, amazing work @mbrett5062!
I've rerolled the patch to reduce some of the superfluous changes, hopefully I didn't mess anything up.
I've yet to really understand the changes made, but I think the test case I wrote was pretty accurate, and this passing is a great sign!
Comment #158
tim.plunkettI don't understand the title change in #112 and #113. It seems like someone tried to merge 2 or 3 issues together?
Retitling as the only bug we know this fixes is the one described in #7 and with a test case in #92.
Comment #159
Fabianx CreditAttribution: Fabianx commentedThat is definitely on my list of issues to review. (if someone else beats me to it, feel free to unassign me)
Comment #160
fubhy CreditAttribution: fubhy commentedNice work on the patch.. However, filtering out (pre)process functions like that if they don't match a certain naming pattern is unacceptable. This prevents custom modules/themes to hook into the theme registry with hook_theme_registry_alter() and manually register custom functions.
I just took a quick glance at the patch so forgive me if I am interpreting this chunk of code incorrectly.
Comment #161
mbrett5062 CreditAttribution: mbrett5062 commented@tim.plunkett, the main change I made to tests was the addition to 'template.php' at the end of the patch. This seemed to be what was missing when you and I arrived at 2 fails each. With this inclusion, all tests pass. The only thing that worries me, is that I wonder if the tests should have passed without it, and am I just cheating the tests.
Comment #162
tim.plunkettThat's done in _theme_process_registry(), which is called by _theme_build_registry().
_theme_build_registry() is also what invokes hook_theme_registry_alter(), so it will still be able to add whatever it needs after that filtering.
Comment #163
mbrett5062 CreditAttribution: mbrett5062 commentedAs noted by @catch in #1804614: [meta] Consolidate theme functions and properly use theme suggestions in core, while this issue is not actually a blocker for consolidating theme functions, this bug becomes more obvious the greater the use of hook suggestions we introduce.
See the following, which will all show this bug. (From theme functions consolidation meta issue)
#1812724: Consolidate all form element templates and add theme_hook_suggestons
#1819284: [meta] Consolidate all form element container templates, and add theme_hook_suggestions
#1812684: [meta] Consolidate all table templates and add theme_hook_suggestions
#1813426: [meta] Consolidate all item list templates and add theme_hook_suggestions
#1595614: [meta] Remove all the theme functions and templates in core that simply output a link. Replace with #type 'link' render arrays
So I think we should move this to critical and get this in now.
Comment #164
tim.plunkettRerolled.
Comment #165
sunHm. This will be painfully slow.
get_defined_functions()
is a huge list.$cache
is a huge list. And$hooks
is a huge list. We're grepping over all functions not only once, but once for every extension in the system.The concatenated $hooks in the PCRE additionally have a good chance of exceeding the maximum limit for the PCRE subject.
We had critical bug reports in the past for some similar code in (IIRC) Schema API already — and that code grepped over all functions only once.
So, hm. While the rest of the code seems to be make sense (but could use some higher-level comments in various spots to explain a bit more what is done and why it is done [instead or in addition of how it is done]), I suspect that we'll run into major performance problems with the proposed implementation. :-/
Off-hand, I can't provide a suggestion for how to address this. The only possible solution I can think of would be a pretty radical change:
Instead of auto-discovering (pre)processor functions, require everyone to register them via
hook_theme()
. Leave the auto-discovery for actual theme_ function overrides and templates only.TBH, I almost guess that this sounds uglier than it actually is. We're generally moving towards a much more declarative system with D8, so the auto-discovery behavior for theme processing functions is kind of a legacy alien in that architecture anyway. It would cut away and resolve the performance problems entirely, and most likely simplify the theme registry processing to a pretty big extent.
Comment #166
rooby CreditAttribution: rooby commented+1 for the declarations idea.
Auto discovery is nice but not really required and not worth a performance hit IMO.
Comment #167
barraponto CreditAttribution: barraponto commentedFrom a themer's DX perspective, overriding theme functions is dead easy. Nothing new to learn, just copy-paste-rename-edit-clearcaches. Implementing new theme functions through hook_theme introduces a lot of (useful) concepts, but it's way too much for simple suggestions.
OTOH, declaring functions in hook_theme would make it easier for themer's to inherit someone else's work. So while I agree with the declarative approach, I'd ask to please make it easier. Right now, declaring a suggestion requires me to declare it's
base hook
,variables
,render element
, etc. Can't I just declare the base hook if I'm not overriding anything?Comment #168
rooby CreditAttribution: rooby commentedDeclaration of the variables, render element, etc. is done in hook_theme and that would remain as is.
This is for declaring specific preprocessor functions for an item already declared in hook_theme so it should be much simpler.
Comment #169
barraponto CreditAttribution: barraponto commentedActually, this is for declaring preprocessor functions for theme suggestions implementations. Declaring a suggestion implementation in a theme's hook_theme should be enough to get its preprocess functions running, right?
Comment #170
jenlamptonI really like @Sun's idea in #165 about declaring, but I wonder what the experience of that would be for a theme dev...
Let's take views as an example. I want to override a specific display of a specific view: views-view-fields--city--default.html.twig. Do I need to register the template before I can override it? I assume no. If I wanted to add a preprocessor for that template file, would I need to register it? I assume yes. I think this is okay since the preprocessor needs to be in template.php anyway, so adding a hook_theme in there to let the system know about it wouldn't be too painful.
Now, let's take item-list--user as an example. I want to add a preprocessor for the user list, but I don't want to change any markup. Please, don't make me add a new template file that just includes item-list.html.twig, but if I have to I will gladly register a new preprocess function in template.php.
I'm also more okay with this approach than I would have been in D7, because I think that with all templates in Twig (fingers crossed) I dont expect there will be nearly as much preprocessing going on to start with. The more savvy theme devs who want to use preprocess should have no problems registering new functions.
However, I think I'd still be happier if we could find a performant way to auto-discover all the preprocess functions as well as the template for the theme hook called.
Isn't there a way we can improve the time it takes to find all the matching functions? In this case, we know what the names of the functions will be, we're not in the same boat as modules where it can start with anything. Can't we sort the functions in alphabetical order or something, and only search the ones that are close matches?
Speaking of how modules do things... what about lazily building up the theme registry instad of doing it all at once? Modules do this by hook, every time a hook is called only the functions that implement that hook are registered. Can we do the same thing for the theme registry by building it up one theme hook at a time? So, for example, when we're on a page with the user list and
theme(array('item_list__user', 'item_list'))
is called, we could register all preprocess functions for item-list--user and item-list, and when we hit a page with node links, we can add preprocess functions for item-list--links to the registry too.Comment #171
catchLazy building the theme registry could work I think, that was one of my intended follow-ups to the initial CacheArray patches (for schema registry too) but I never got to it. At the moment we cache a 'full' theme registry, then consult that at runtime on CacheArray misses, we'd need to get rid of that full cache and try to do the minimum in the CacheArray miss to populate it correctly. Only question is how much work that ends up being each time there's a cache miss vs. buidling the whole thing at once but we might be able to do a partial build then fill in the gaps too.
Comment #172
sunI can't see how lazy-building improves the situation with #165 — we'd still have to iterate over all functions that are currently defined in order to dynamically find applicable preprocessors and processors.
I'd actually think it would make the situation worse, because we're not able to plan and optimize that discovery ahead of time; i.e., the loop over all functions would potentially have to re-run for every single
theme()
call that specifies a different theme hook name. For example, just'input__foo'
and'input__bar'
are different and need to discover different (pre)processors.Aside from that, @jenlampton's interpretation of my proposal in #170 appears to be correct — everyone would only have to declare (pre)process callbacks, and because you're in working in PHP/template.php already, having to additionally register the callback in
hook_theme()
doesn't really look very unusual/cumbersome to me.Comment #173
tim.plunkettJust to clarify, which of the following would you have to explicitly declare?
With only node.tpl.php present:
1. mytheme_preprocess_node
2. mytheme_preprocess_node__article
With node--article.tpl.php present
3. mytheme_preprocess_node__article
As I understand, we're only changing for case 2. If that's true, then this sounds good to me.
Currently, #1 and #3 work currently AFAIK, and adding an extra step for those to continue to work sounds unfortunate to me.
Comment #174
sunFWIW, we actually have some pretty heavy name clashes with the auto-discovered
hook_process_THEMEHOOK()
already:http://api.drupal.org/api/search/8/_process_
Quite a couple of those are NOT theme process functions, but form element #process callbacks. It's a mere coincidence of extreme luck that those functions are not invoked as theme process functions. ;)
I've tried to whip up a proof of concept patch for explicit (pre)process function declarations over the past hours, but the current theme system code is beyond my code sanity threshold. So after debugging and backtrace-ing for hours, I'll now approach the reverse, rewrite and re-implement the whole thing more or less from scratch as a proper service, ensuring that the resulting registry is mostly identical to the current. Totally requires a separate issue, of course; #1886448: Rewrite the theme registry into a proper service
Comment #175
tim.plunkettSelfishly reuploading a reroll of #62 for D7
Comment #176
xjm@sun and @timplunkett discussed this issue in IRC, and it sounds like it's going to be really hard to make progress here without #1886448: Rewrite the theme registry into a proper service. I bumped that issue to critical; let's postpone this on that to make it clear what our current status is.
Comment #177
kevinquillen CreditAttribution: kevinquillen commentedI think this may be the issue I am having, but I am not 100% sure.
I am currently implementing the Foundation theme in Drupal 8 as Twig, and noticed functions like this are not working:
etc.. if I edit the theme .info.yml file and remove the 'engine' attribute, those functions begin to work, but I would assume because D8 thinks up front that the theme is phptemplate? I noticed that the twig_engine function does not look for theme functions like phptemplate_engine does, which is what the patches above seem to attempt to address.
I have a BoF tomorrow for Foundation 4 in Drupal 8 and would like to crank through on the conversion but this might stop us in our tracks (for the time being).
Comment #178
Fabianx CreditAttribution: Fabianx commentedHi #177, Hello from the Coders Lounge at DoubleTree.
We have that fixed within the removal of double engine code from http://drupal.org/node/1806478.
For now you can just add to the twig engine that it should search for theme_ functions as well.
Please feel free to base your theme upon the Twig-Megapatch from http://drupal.org/node/1987510.
Thanks! Hit us up in the coders lounge tomorrow or today / yesterday in Coders Lounge at Double Tree.
Thanks a lot,
Your Twig-Team!
Comment #179
kevinquillen CreditAttribution: kevinquillen commentedThanks Fabianx, that's what I did short term (change twig_theme()) - I will take a look at that patch.
Comment #180
jenlamptonI think this is also going to end up being a duplicate of #2004872: [meta] Theme system architecture changes.
Comment #181
jenlamptonclosing as dupe.
Comment #182
catchI'm not clear what this is a duplicate of.
Comment #183
yannickoo@catch #180? #2004872: [meta] Theme system architecture changes
Comment #184
catchThat's a meta issue though, there needs to be a specific issue with a patch to mark this as duplicate of, and that issue should be a critical bug too (or be prepared to not fix it at all for 8.x).
Comment #185
jenlamptonOkay, how about dupe of #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter()
It's got a patch on it, and it should solve this problem :) I'll bump up the priority over there.
Comment #186
tim.plunkettComment #187
star-szrThanks @tim.plunkett!
As noted in #1751194-35: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter(), that issue alone doesn't solve this problem. Or at least doesn't make the test case in #96 pass. I think it will make this issue easier to solve though, even if it ends up getting solved from the theme registry issue.
So… tentatively bumping to 8.x and re-postponing for now. Hopefully we can get this solved soon.
Comment #188
markhalliwell#2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() combined with #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() will fix this issue in 8.x. Because that issue is a major shift in how the theme system will work, bumping this back to 7.x so @tim.plunkett's patch in #175 can be worked on and committed against 7.x.
Comment #189
PavanL CreditAttribution: PavanL commentedComment #190
PavanL CreditAttribution: PavanL commentedComment #191
sunComment #192
markhalliwellThis is for 7.x. The 8.x equivalent #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() already has the parent.
Comment #193
markhalliwellI'm moving this back to 8.x. We're not going to be moving forward with the addition of the
hook_theme_prepare()
API in 8.x (which is now postponed to 9.x). I'm also going to try and take a stab at this sometime this week.Comment #194
markhalliwellSorry for creating a lot of noise (bad code day :)
Comment #195
sunThe problem is no longer abstract/hypothetical; we have a real use-case in core now.
AFAICS, the remaining task is to extract the original/scope-creep changes from #1886448: Rewrite the theme registry into a proper service, so that they can be committed here. — At least, that appears to be the only solution of all that have been proposed thus far that actually has (had) a working implementation.
Comment #196
andypostAnother use case is #1962846: Use field instance name for header of comment list, drop comment-wrapper template
Comment #197
catchBumping this to a beta blocker since there's a decent chance it'll rely on non-trivial API changes to fix.
Comment #198
jessebeach CreditAttribution: jessebeach commentedI've heard-tell that these changes might include registering preprocess functions for a theme implementation rather than a discovery process for preprocess implementations. So that means we:
hook_theme_registry_alter
(docs) for all the existing implementations of specific hooksThis feels like a big impact for core, but not-so-huge for contrib. I'd lobby that it not block the beta cut. The patterns we'd move to already exist in other places meaning the registering of functions (similar to #pre_render) on what's essentially an info hook (
hook_theme
).Comment #199
andypost@jessebeach Take a look at #1962846: Use field instance name for header of comment list, drop comment-wrapper template to use additional preprocess function for comment field I need anyway register theme implementation now, the same applies to node title field now. If you think that there's other way - please explain
Comment #200
markhalliwellI cannot seem to get enough time to devote to this. I'll still follow, review and offer my feedback but I cannot work on code dev. There's still a lot of code that could probably be leveraged/moved from #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK().
Comment #201
hass CreditAttribution: hass commentedVery good that this is a beta blocker... :-)))
Comment #202
effulgentsia CreditAttribution: effulgentsia commentedSince #1751194: Introduce hook_theme_suggestions[_HOOK]() and hook_theme_suggestions[_HOOK]_alter() is now fixed for D8 (great job, everyone who worked on that), my concerns from #6 are no longer relevant, so I support this issue. I'm pretty tempted to try a drupal_alter()-like approach (see #8), even though #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK(), which would have made that easier, has been bumped to D9. But, that just mean instead of using drupal_alter() as-is, we need a copy of it that works for the naming pattern of *_preprocess_*().
@sun and others: do you foresee a problem with that working out? Looks like the only reason this issue was tagged as beta blocking is due to #195's suggestion to use a manually specified 'preprocess' array in each hook_theme() implementation, but that was rejected in #1886448-96: Rewrite the theme registry into a proper service as bad DX. I don't really see why a drupal_alter()-like approach couldn't work though, in which case, there's no need for this to be beta blocking.
Comment #203
hass CreditAttribution: hass commentedI also found bug #2257667: Theme hook template_preprocess_item_list__search_results() not fired, but was pointed here by sun. There seems to me a lot of suggestions broken.
Comment #204
tim.plunkettFrom November 2010 in #6:
From January 2013 in #163 (when we had a passing patch):
We knew of this bug before D7.0 came out, and it didn't block release. The critical status was in order to get some momentum going, and really isn't applicable now.
Comment #205
xjm@catch, @alexpott, @Dries, and @webchick discussed this issue this morning and agreed that it is not beta-blocking.
Comment #206
markhalliwellComment #207
andypostOne more issue postponed on this #2229355: Field template suggestions are colliding
Comment #208
markhalliwellSorry. I did not get to this at DC Austin and I really do not have the time now to start digging into this now. Hopefully someone else can tackle it.
Comment #209
jhodgdonThis issue badly needs an issue summary update. I read the first few comments from 4 years ago, but ... at 208... what's the plan? What's the problem being addressed? etc.
Comment #210
akalata CreditAttribution: akalata commentedComment #211
akalata CreditAttribution: akalata commentedComment #212
akalata CreditAttribution: akalata commentedComment #213
akalata CreditAttribution: akalata commentedComment #214
mgiffordComment #215
lauriiiI did some debugging for this. Uploading what I've been testing around. Probably tests in the patch are most useful.
Comment #216
jhodgdonThe summary is looking much better. It's still lacking in the Problem section ... maybe an example, like "For instance, on the foo__bar hook suggestions, you'd want _____() to be called, but it isn't." or something like that. Then in Proposed Resolution, it would be helpful to state something like "Functions named ... will be automatically invoked", if that is the plan, or to state what the plan actually is. Reading the summary, I still have no clear idea what the plan is.
And when you have a patch that is ready for review, or even that you want people and/or the bot to take a look at (even if it still has problems), don't forget to set the status to "needs review".
Comment #217
lauriiiComment #218
jhodgdonThanks, that clears it up!
Comment #219
lauriiiI've been wondering how this should be done.
a)
With only node.tpl.php present:
1. mytheme_preprocess_node
2. mytheme_preprocess_node__article
With node--article.tpl.php present
3. mytheme_preprocess_node__article
b)
With only node.tpl.php present
1. mytheme_preprocess_node
2. mytheme_preprocess_node__article
With node--article.tpl.php present
1. mytheme_preprocess_node
2. mytheme_preprocess_node__article
I think if we do this way a) it will create unnnecessary complexity to it. For me it it sound like it should be more like a function level filtering so that you don't have to do the filtering inside the function.
Comment #220
lauriiiStill some very rough messing around but just a little more usable format.
Comment #221
davidhernandezRE #219 I would say 'b'. mytheme_preprocess_node should always be run.
Comment #222
markhalliwellYes, "b". Preprocesses should always be accumulative, i.e.:
node__article__sidebar
should execute the following hooks in this order (if found):This allows
node__article__sidebar
to inherit whatever the base hook (and suggestion) preprocess implements. It is then up to the very specific preprocess suggestion to change/remove whatever is inherited (if needed).@effulgentsia, could you elaborate more on #202? I'm really not sure I follow the "alter" method proposed.
Comment #223
markhalliwellAdding back the backport tag I removed in #188 when I thought this was going to be a 7.x only issue.
Comment #224
lauriiiThis might be impossible to implemen without breaking the caching completely. If preprocess functions would be cached with the dynamic theme suggestions we would need some kind of cache tagging etc to make it work at all. Lets see how many things I'll break with this.
Comment #226
lauriiiComment #227
lauriiiLast patch was messed up :P
Comment #230
lauriiiComment #231
davidhernandezI ran based on #230. This was literally just the default front page after installation; standard profile.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=550de0b43acdf&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=550de0b43acdf&...
Comment #233
lauriiiComment #234
rteijeiro CreditAttribution: rteijeiro commentedFixed a few nitpicks in comments.
Comment #235
rteijeiro CreditAttribution: rteijeiro commentedFixed a small typo.
Comment #239
lauriiiI was talking with Cottser on IRC and we both agreed that this is probably something that is not possible to get inside core anymore and would need lots of refactoring for the theme registry to make it work how it should work. In order to make it work we would require that preprocess functions are being generated somewhere else than theme registry because its concidered to be static. That would cause regression for hook_theme_registry_alter. Also the fact that preprocess functions would not be cached to theme registry would cause huge impact on the performance side. Im still leaving this open if there is anything else to say.
Comment #240
markhalliwellThis isn't a "feature", it's a bug/task (other postponed issues require the ability to preprocess specific suggestions)... it needs to "go in".
I'm not sure how or why this has deviated from the proposed solution in #175 by @tim.plunkett. I'm also not sure why there the bulk of this was moved to run-time and not via the theme registry (which is cached).
Despite #231 (which relates to the run-time discovery), performance tuning can be done in this related issue (which is similar to what Tim kind of semi-implemented in #175).
Comment #241
tim.plunkett#175 is actually a reroll of #62, which has been working for over three years, and was a reroll of the work done by @dvessel four years ago (see #19 and #956520-30: Available theme hook suggestions are only exposed when there are preprocess functions defined)
Comment #242
markhalliwellAh, my mistake. I just looked for the previous older patch (didn't really read the comment). Regardless, I would be more inclined to stay with that approach rather than the current iterations, unless I'm missing something...
Comment #243
lauriiiLets see how many test failures I can cause with this :P
Comment #245
lauriiiLittle bit less crappy patch :P
Comment #249
lauriiiComment #251
lauriiiThis should fix the tests
Comment #252
lauriiiI created a performance test on default Drupal frontpage view printing 50 of 150 nodes.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=55323a80ebb82&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=55323a80ebb82&...
Comment #253
rteijeiro CreditAttribution: rteijeiro commentedJust fixed a few nits.
Comment #254
Fabianx CreditAttribution: Fabianx for Acquia commentedThe kind of profiling we need here is cold-cache performance or benchmarking just the build of the theme registry, when there are lots of to be discovered functions and lots of modules ...
Comment #255
lauriiiProfiled this without any caching.
Run 553b9a86a14e1 uploaded successfully for drupal-perf-lauriii.
Run 553ba00bcf766 uploaded successfully for drupal-perf-lauriii.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=553b9a86a14e1&...
Run 553b9a86a14e1 uploaded successfully for drupal-perf-lauriii.
Run 553ba42a8e87e uploaded successfully for drupal-perf-lauriii.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=553b9a86a14e1&...
Comment #256
lauriiiApplied latest patch from #2339447: Improve theme registry build performance by 85% with my changes.
Run 553ba8c2c449d uploaded successfully for drupal-perf-lauriii.
Run 553bb0137a0c9 uploaded successfully for drupal-perf-lauriii.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=553ba8c2c449d&...
Run 553ba8c2c449d uploaded successfully for drupal-perf-lauriii.
Run 553bb054a0d57 uploaded successfully for drupal-perf-lauriii.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=553ba8c2c449d&...
Comment #258
lauriiiHopefully tests are passing now
Comment #259
markhalliwell#256 shouldn't have been uploaded with the code from #2339447: Improve theme registry build performance by 85%. That is a separate issue and really has nothing to do with this one. I understand performance is something we should be concerned with, but please try to limit the patches in this issue to the task at hand and simply reference that issue when necessary to avoid further confusion.
Edit: p.s. Thanks @lauriii! Not trying to discourage you and really do appreciate you tackling this. I just saw how easily this issue/patch could have caused mass confusion is all.
Comment #260
Fabianx CreditAttribution: Fabianx commented#259: That is not true, because we do a _lot_ more checking of prefixes now as far as I have understood so we should show at least that we can improve performance for making that lookup efficient. (and then move it again to a follow-up)
Comment #261
star-szrI think this probably can't get in until #2339447: Improve theme registry build performance by 85% gets in, is what it boils down to.
I think removing these lines entirely (as far as I can see) is a kind of API change. More specifically:
This logic could be re-added within postProcessExtension() I'd think.
Since this is duplicating the docs from processExtension maybe we should just refer to those docs if possible, instead of getting into this type of rabbit hole:
This might be copy and paste but _theme() doesn't exist anymore. I'm not totally sure the best place to point to for this documentation, unless before it was just pointing to the inline comments in _theme (now \Drupal\Core\Theme\ThemeManager::theme() I believe).
Minor: Stars don't align.
Comment #262
joelpittet@Cottser that performance issue should have no effect on this and if it gets in the relative performance regression shouldn't change for this bug fix.
Maybe you and @lauriii can work on pushing this bug fix out the door without that other patch?
Comment #263
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedWhile the other patch alone won't help, to me it looks like this could really benefit from using the same lookup table that would be introduced in #2339447: Improve theme registry build performance by 85%. Specifically the section of code that sun refers to in comment #165.
Comment #264
lauriiiRemoved the performance improvements from this patch. I also fixed the nits from Cottser.
Comment #265
Fabianx CreditAttribution: Fabianx as a volunteer commentedThe patch looks ready, once we can use drupal_get_prefix_grouped_functions() from the other issue, my performance concerns are pretty much moot.
Postponing on that shortly.
Comment #266
lauriiiNot being postponed anymore
Comment #267
lauriiiYay, this should be a little faster now!
Comment #269
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedTests seem to have failed because of something unrelated to the patch... Here's another iteration. I think this can be a further improvement for performance and gets rid of the really big regexp. Hoping this one gets to the tests now...
Comment #270
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedSorry, forgot about the interdiff. :) It's attached. And marking needs review in hopes of getting a test run.
Comment #271
lauriii@Antti: Thanks! We tested that in the other issue and there it seemed to be slower than running the regexp. Don't know for sure if that applies here but lets test it out
Comment #272
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commented@lauriii: Oh okay, I think it might at least scale better and be less in danger of hitting the max limit for regexp size though. To be honest the second one is probably an unlikely issue, PCRE's limits are pretty high these days.
Comment #273
markhalliwellThis should have a comment above it explaining what it is for, just like
$this->processExtension(...)
.The functions/hooks are not "missing" they're being "automatically discovered".
This should be a description, not a
@see
comment (which should be added at the end of the doc block).This should be a class, not
object
.I would even further surmise that the method signature should include the expected class of
$theme
.Generally speaking, these are "preprocess functions" not "processor functions".
Specifically speaking, this entire code addition is for allowing the "preprocess of theme hook suggestions".
I only say this because it's initially confusing to read since in the history of the theme system there were separate process functions before.
All comments in this code should really be updated to reflect the either the general or specific concept.
Needs to be a single line comment.
Comment #274
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedComment #275
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedI realized the regexp still needed quite a bit of work. This one should work and be fairly fast. It now requires the considered processor to contain "__" unlike the older version. It would seem to me like that's needed since this is about preprocess functions for suggestions.
Also tried to address 1, 3 and 4 from @markcarver's review.
Comment #276
lauriiiComment #281
lauriiiComment #283
Fabianx CreditAttribution: Fabianx as a volunteer commentedThis is not gonna work reliably, the theme registry can load code at any time.
You will need to diff already seen functions with new get_defined_functions() - as in my original patch on the other issue.
----
I am pretty sure tests are now failing, because it should be:
$processors['mymodule_preprocess_node__article'] = 'mymodule_preprocess_node_article'
in the end ...
That is why we had array_combine before.
Comment #284
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedComment #285
lauriiiCaching grouped functions might not be worth it so I removed that from the patch.
Comment #286
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedI believe I improved on the cached version here by using a different approach for saving the seen functions resulting in less memory used and better overall performance. I think it could be worth keeping as Iarge and complicated sites could still see something like 500-1000 ms (possibly a bit optimistic back of the envelope calculation) saved with it.
Comment #287
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedJust removed the wrapper function from theme.inc.
Comment #288
lauriiiProfiled that with the set we had on the other issue #2339447: Improve theme registry build performance by 85% and looks pretty impressive:
Comment #289
Fabianx CreditAttribution: Fabianx as a volunteer commentedYes, I agree. We need a comment however that this approach works, because functions can only ever be added and never vanish. (That is why this works so well.)
And yes, that was kinda my original implementation for $seen :).
We could implementation=wise directly rely on $this->seenFunctions() - no need to assign back and forth. Also makes the code a little simpler ...
Comment #290
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commented@Fabianx: you're right, the flipping around is not useful. I mistakenly thought it would be. I removed that and changed to just keeping the list with function name keys and boolean values like your original version. Added a comment as well.
Comment #291
star-szrReviewing this. I redid most of the issue summary to focus on what is actually happening now.
Comment #292
andypostThis should be deprecated not removed
getEditable() should there, how it passes is a question
Comment #293
lauriii@andypost: We discussed about 1. with @alexpott and it can be removed. It's considered to be prioritized change since its follow-up for a major issue.
Comment #294
star-szrJust noting the API change in the issue summary.
Comment #295
lauriiiComment #300
star-szrSome minor stuff, not a complete review at this point. Obviously getting the test fails fixed would be higher priority :)
"before the first underscore"
Should we be adding 'template' to this list of prefixes? Seems like template_preprocess_suggestions__kitten should work (if it doesn't already).
Minor: cssSelect.
We should probably test modules using the specific hooks, not just themes.
Comment #301
lauriiiJust trying to fix the tests first
Comment #303
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedNot sure I understand what's the direction taken with the latest patches. Why was the check for the existence of the base hook removed?
Comment #304
lauriiiI'm sorry I didn't remember to leave a comment what we are trying to solve here because we talked about this on the sprints at DrupalCon Los Angeles where we decided to support preprocess functions even though a template wouldn't be provided. Also the previous logic didn't work since the preprocess function got added to the base hook and that way it got triggered for all the children of the base hook. Also on the theme manager we used to replace the preprocess functions with the base hooks preprocess functions but we don't want to do that anymore because children's preprocess functions can be different now.
Comment #305
lauriiiComment #307
lauriiiComment #309
lauriiiComment #311
hass CreditAttribution: hass commentedComment #312
lauriiiLets see how many tests I'm able to break with this.
Comment #313
joelpittetFrom #300 I did the nit picks for you @lauriii but maybe you can respond to #300.2 and #300.4?
Nice work to get it all green!
Comment #314
tim.plunkettThese should start with a verb with an 's' like "Completes the theme..." and "Gets all user functions..."
Can we get a follow-up to add an interface for this class? Especially considering it is a service.
I would just remove "even", this has to fit on one line.
public function
Any reason for not using the API?
\Drupal::service('theme_handler')->setDefault('test_theme');
Comment #315
tuutti CreditAttribution: tuutti commentedAdded some more test coverage and fixed things @tim.plunkett mentioned.
Comment #316
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAre we sure this is still needed?
Oh, I see, it is part of postProcessExtension now ...
Yes, I think we should add 'template' as prefix.
Overall looks great, 'template' could be follow-up, too - if needed.
Comment #317
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedI believe the suggestion preprocessors must be added to the theme hook preprocessor lists in order. That is: "__kitten" must be processed before "__kitten__flamingo" independent of the prefix order. Otherwise "__kitten__flamingo" cannot pick up the "__kitten" preprocess function.
This is not currently the case. Order depends on what get_defined_functions() happened to return. Another thing is that this currently introduces base hook chaining which has not been allowed as a rule so far.
If I'm right about my observations, maybe just going with dvessel's version where just the base hook preprocessors were inherited would be better to keep things simple?
Comment #318
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#317: Yes, that was my concern, too, but I thought we only allow one level anyway ...
And for all things being able to do:
hook_preprocess_foo__bar() is much better than not being able to do so ...
If we need to get crazy and support hook_preprocess_foo__bar__baz(), then we would indeed need to order by length of key to do so reliably.
I would not be opposed to base hook chaining as long as we end up with a deterministic order.
Comment #319
lauriiiUnnecessary double line change
Comment #320
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedI think this should be enough to ensure all the preprocess functions are added in the right order. Removed a never-reached section from the hook processing and tried to choose more descriptive variables.
Also improved on some of the comments for #273.5 and removed the extra newline but at least #273.2 still remains.
Still probably needs work, I suspect things like suggestion hooks might not get called properly.
Comment #321
star-szrDoes this already handle base theme preprocessors coming before subtheme preprocessors? Either way, that probably deserves test coverage I'd say.
Comment #322
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedLooks pretty good to me :)
Comment #323
lauriiiSo we talked shortly about this on yesterdays Twig call. What people on the call agreed was that we should include the template preprocess functions here because it would be bad DX to accept using specific theme suggestions for theme preprocess but not template preprocess.
Adding template functions in the post process would add unnecessary complexity if we would test where the function is located. Currently we accept template preprocess functions only from modules. We thought we could remove that limitation because of the docs are saying "Should be implemented by the module that registers the theme hook, to set up default variables." so we already suggest people to not use it anywhere else instead of forcing (according to docs). Anyway there is already working work arounds to get that limitation out.
Comment #324
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedNeeds work, only marking needs review to get a test run.
Changes:
Doesn't chain the base hook definitions. The alternative is to change ThemeManager's logic for including the base hook files and calling suggestion hooks but I'm not sure about what the gain from the effort would be.
Just uses the suggestion hook's preprocess functions instead of merging with base. That should now work after a fix in this to postProcess that caused the suggestion hooks to get the preprocessors in the wrong order after they were merged in from the base hook.
Checks for the base hook again... Sorry, but I don't see a problem with this and it just seems more robust to me. If there's an argument against it I'll be happy to hear it though.
Comment #325
lauriiiWe need test coverage so that the change on #324 doesn't break anything. It is also important part of the way theme system works so its good to have later on too.
Also did a small tag clean up. Don't think we need all these.
Comment #326
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#323: Could you elaborate some of what you mean there?
I don't actually get what the change will be ... Thanks!
Comment #327
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedAdded a few tests for a current problem in the patch: an implementation of a suggestion without it's own preprocess functions won't inherit the preprocess functions from less specific suggestion levels.
Comment #328
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedComment #330
lauriii#326: So the idea is that instead of removing template functions out of the scope of this issue we agreed on covering the template functions here to not cause any regression for the DX. The idea what we thought it would work was this:
instead of overriding the previous template functions:
or simply not adding template functions
we want to call template function for each theme suggestion like this:
Comment #331
lauriiiSo when we'll do this we need to check if there is available hooks on lower levels so they can be added for the same stack.
Comment #332
davidhernandezWhy do we need to support
template_preprocess_node__article
?Comment #333
lauriiiI think the biggest reason for that is the learning curve. Why would it make sense to have them for hook_preprocess_hook if not for template_preprocess_hook?
Comment #334
davidhernandezGoing back to the comment in #323, what I remember is we agreed that it was ok to leave the ability to use template_preprocess_* from a theme. Not because it was desired functionality, but because preventing it would be too complex as it isn't apparent where the suggestion came from. We would just state, for the record, that it was a bad idea to do.
Please correct me if I'm wrong, but my understanding is that the point of template_preprocess_* functions is that they run first and guarantee a way that the preprocessing done by the module that declares the theme implementation will always run first. All of other modules and themes should be using hook_preprocess. If so, the module that should use template_preprocess_node is the node module, and the node module would have no reason to use extended suggestions. If it did, they probably would have been declared separately.
I don't mean to say the additional suggestions be stopped, if they are a natural result of fixing the hook_* suggestions. It just didn't strike me as being worth additional complexity to add, if not already there.
Comment #335
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#334: Yes, however I as a module author could have a generic theme => 'map' type and then have 'map__red' be a subtype, where I declare both template_preprocess_map and template_preprocess_map__red ...
Comment #336
markhalliwellYes,
template_preprocess_THEMEHOOK__SUGGESTION[__SUGGESTIONS]
is needed (both modules and themes need this).For a real world use case scenario, the Icon API module could greatly utilize this:
Have to manually define "different" theme hooks just to differentiate between icon types:
http://cgit.drupalcode.org/icon/tree/includes/theme.inc#n27
Invokes an additional theme call for the specific icon bundle's renderer theme hook:
http://cgit.drupalcode.org/icon/tree/includes/theme.inc#n91
It's basically the difference of having to manually define additional theme hooks and hack in special "variation" code to deal with "inheritance"; opposed to using proper theme hook suggestions in the first place.
template_preprocess_icon()
template_preprocess_icon_sprite()
<- different theme hook "icon_sprite", essentially duplicates code required to "inherit" from the above "parent" theme hook.vs.
template_preprocess_icon()
<- preprocesses all icons.template_preprocess_icon__sprite()
<- would be invoked after the above to preprocess "sprite" specific icons.edit:
This allows the module that created theme hook (Icon API in this case) to run it's necessary preprocessing first before any module or theme decides to do it's own preprocessing to add/remove what was initially provided:
MYMODULE_preprocess_icon()
MYMODULE_preprocess_icon__sprite()
MYTHEME_preprocess_icon()
MYTHEME_preprocess_icon__sprite()
This is how basic preprocessing currently works (module that created theme hook uses template_preprocess_* and then modules/themes use hook_preprocess_*). This issue is about expanding that existing pattern to preprocess theme hook suggestions as well.
Comment #337
davidhernandezOk, that answers my question.
Comment #338
lauriiiI was investigating this and was able to track down the problem. The problem is that some preprocess functions are created before postProcess and therefore they have wrong values (not supported by postProcess) in their array.
Comment #339
winstonchurchil99 CreditAttribution: winstonchurchil99 commentedUntil is fixed you can use this MYTHEME_preprocess_node__SUGGESTION by adding this in your template.php :
Comment #340
Antti J. Salminen CreditAttribution: Antti J. Salminen as a volunteer commentedWe exchanged ideas with lauriii and here's some unfinished work on fixing the current main issue with the patch based on that. Just triggering a test bot run, still needs work.
Comment #342
lauriiiThis should fix some of the existing test fails. Lets see if this introduces new one.
Comment #346
lauriiiWe need to inherit the preprocess functions from base hook if base hook has been defined. This should fix some of the remaining failures.
Comment #347
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC - I don't have further performance concerns.
Nice work on re-using the new algorithm.
Comment #348
XanoGlad to see the code itself has been RTBC'ed! My feedback applies to the documentation only:
@var array
is not specific enough. It looks like this should bestring[]
.@var array
is not specific enough. It looks like this should bebool[]
, with an additional description to document that keys are function names, and to explain that this array format was chosen because key lookups are faster than value lookups.Wait, wut? This is no coherent sentence.
@var array
is not specific enough. This needs a more specific description of what is in the array.Same here.
This method always returns an array. The type cast is not necessary.
Hooks registering hooks? Should maybe be modules registering hooks?
@return array
is not specific enough.Comment #349
cilefen CreditAttribution: cilefen commentedThis is 1, 2, 3, 6 and 7. I don't know how to document $cache.
Comment #350
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThis are minor doc nits that don't need to block this as we reference the building up theme registry already since ages just as array $cache, which we build over time.
It is just an array of hooks.
If we had good documentation elsewhere on that I would agree, but we don't, so we should open a follow-up to clean up docs during RC phase. (which is still unfrozen then).
Comment #351
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI take that back, I found the docs!
"$cache: The theme registry that will eventually be cached; It is an associative array keyed by theme hooks, whose values are associative arrays describing the hook:"
So should probably be:
as in https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Theme%21R...
Comment #352
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAdded a proposed commit message. I would propose to give everyone credit that has more than just 1 comment as this is a really really old issue.
Comment #354
cilefen CreditAttribution: cilefen commentedIt is clear now why we need the typecast. How about this for documenting the parameter? It is so well documented in processExtension().
Comment #355
XanoWe did not need the type cast. We usually don't, and when we do, we must document why.
Comment #356
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThanks for the fixes, back to RTBC!
Comment #357
alexpottI get moving the method to the object so we can unit test. But also changing the logic to store seenFunction and groupedFunctions is not necessary. There's been no discussion of the memory usage vs performance gains of this change.
Comment #358
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedDiscussed with alexpott, lets make the statefulness a follow-up and remove the seen* and groupedFunctions* state from the class.
It is just one more call to get_defined_functions(), which should be fine for now.
Comment #359
lauriiiAdded some documentation to theme.api.php and reverted the logic change
Comment #360
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThanks and back to RTBC.
Comment #361
catchDo we still need the first three entries in system_theme() once this is in? https://api.drupal.org/api/drupal/core!modules!system!system.module/func...
Comment #362
markhalliwellNo, they should be able to be removed once this is in.
I had a moment of hesitation when I saw two of them also declare
'render element' => 'elements',
, which implied they were overriding the base hook, but they are not:https://api.drupal.org/api/drupal/core!modules!block!block.module/functi...
If we want to remove them after in a separate issue, that's fine. I would suggest that it be done in this issue though or, at the very least, maybe upload a patch with those removed to verify that all tests still pass?
Comment #363
lauriiiNo they cannot be removed since template overrides are still not being picked from the modules. This only affects preprocess functions and where they are being triggered.
Comment #364
markhalliwellThat shouldn't be true, if it is... I would imagine then that something severely broke along the way. It was just the preprocessing of suggestions that didn't work.
Comment #365
davidhernandezModules are not checked for theme overrides, as Lauri said. Those entries are there so that the system module can provide those block specific template files. To my knowledge this is how it has always worked, no? We have a number of cases in core where we do this. This issue though makes the more granular preprocess functions work.
Comment #366
star-szrYes, if we're changing that it should be a separate issue I think.
What we would be able to potentially replace with this committed is some logic in preprocess that could be replaced by using a specific preprocess function.
Comment #367
markhalliwellProbably. I could have sworn that template discovery also included the path where the original template was located, but I could be mistaken... I'd have to manually step through again. Ok, sigh, this is just another theme system "gotcha".
It's fine if a follow-up issue is created to address that annoyance. This specific issue is already too long and just needs to get in and backported.
Comment #369
star-szr1 fail in Drupal\config_translation\Tests\ConfigTranslationUiTest:
"Translatable storage setting" found Other ConfigTranslationUiTest.php 755 Drupal\config_translation\Tests\ConfigTranslationUiTest->testFieldConfigTranslation()
Taking way too long to run locally, so hitting retest.
Comment #371
star-szrIt will go back to needs work if it fails again.
Comment #372
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 5072353 and pushed to 8.0.x. Thanks! I credited everyone with more than 1 comment as per @fabianx's idea.
Yes let's handle the storing of state in
Registry::getPrefixGroupedUserFunctions()
in a followup.Thanks for adding the beta evaluation to the issue summary.
Whilst this is marked "needs backport to D7" I would strongly suggest opening a new issue. Since we're at 300+ comments.
Comment #374
davidhernandezWow. Super big thanks to Lauri. I know he put a huge amount into this one.
Comment #375
lauriiiyay!
Comment #376
star-szrTruly an epic issue. Thanks all, and yes especially @lauriii for being persistent and getting this past the finish line when others (including myself) didn't think it could be done :)
Comment #377
BerdirFYI: This introduced a small but somewhat annoying* regression.
I had a "suggestion" in a module with a base hook because I wanted kind of the opposite of this issue.. re-use preprocess functions but with a different template, in a module. And because suggestion detection doesn't work for modules, I had explicitly defined it in hook_theme() with 'base hook'. I didn't follow the naming scheme for suggestions, though (Which is to use __/--).
That worked fine up until now, but the new completeSuggestions() method hardcodes the assumption that __ is used to separate suggestions. So suddenly no preprocess was called anymore for my template and my output was gone (in my case, it was a views grid template). Renaming my suggestion fixed it.
I'm not sure if that is a bug that we should fix (and for example always look at the actually defined base hook in that method no matter which name it has or if I was just mis-using the system? (That's the tricky part with regressions, even if someone was using something in an unexpected way, breaking it is still a regression).
Mostly, I just wanted to make others aware of it, don't care that much if this is fixed or not, I can live with renaming my template. If we don't fix it, then maybe mention it in the change record or have one for this?
* annoying because it was quite hard to track down.
Comment #378
lauriiiThat is a bug I think. The logic might be possible to change work so that it doesn't require the __ pattern so I created #2559825: Preprocess functions from base hooks not triggered for theme hooks not using the __ pattern for this.
Comment #379
markhalliwellOk, let me try and understand this:
If that is what you're saying and it's true, then I suppose that could be considered a regression, yes. If a theme hook defines a "base hook", it should (essentially) merge in that base hook's information (including it's base hook preprocess functions).
That being said, I don't necessarily think that this is about "suggestions" specifically. However, let's move this discussion over to the other issue. This one is already so long.
Comment #380
hass CreditAttribution: hass commentedD7 now.
Comment #381
markhalliwellIt was stated that we should really move the backporting of 7.x to a new issue (since this one is so long). I agree and have created this related child issue.
Comment #382
hass CreditAttribution: hass commentedThis patch seems not fixing the following suggestion, but sun told me it will.
and this is also not working. No idea why. It looks 100% like SearchEmbeddedForm.
Comment #383
lauriiiWould you mind showing me the exact code showing what you are trying to do or post a failing test?
Comment #384
star-szrThe first one is missing preprocess. At this point I think we should move to a support request issue, it's painful now that we are on page 2.
Comment #385
hass CreditAttribution: hass commented@laurii: http://cgit.drupalcode.org/google_analytics/tree/google_analytics.module...
@cottser: Should I reopen #2257667: Theme hook template_preprocess_item_list__search_results() not fired referenced on top?
Comment #386
markhalliwelledit: nevermind... I misread. Let's just open that other issue back up... this one is way too long
Comment #387
star-szrOr via the suggestions API (hook_theme_suggestions(_alter)).
@hass you should be able to change the function to
google_analytics_preprocess_item_list__search_results
(note the commented out line was missing 'preprocess_' and then you should be able to remove the condition for theme_hook_original. Works for me.Edit: If it's still not working for you, yes let's convene in that issue you linked, I'm following it now.
Comment #388
hass CreditAttribution: hass commented@Cottser: Thanks! Gave you the credit for #2256633: Search results counter is missing in search result pages.
Comment #390
effulgentsia CreditAttribution: effulgentsia at Acquia commentedThanks, everyone, for all the great work on this issue.
This function is pretty hard to make sense of. The PHPDoc is scant, and the implementation is hard to follow (at least for me it is). That difficulty proved a challenge for working on #2559825: Preprocess functions from base hooks not triggered for theme hooks not using the __ pattern, and so I opened #2848242: Improve variable names and inspect and document logic of Registry::completeSuggestion() and Registry::mergePreprocessFunctions() in the hopes that it can be improved.
Comment #391
donquixote CreditAttribution: donquixote commented