Problem/Motivation
template_preprocess_HOOK can now be defined directly on hook_theme.
Let's move core implementations to direct callbacks.
Steps to reproduce
N/A
Proposed resolution
Convert them to the appropriate new system.
Create children issues.
- field preprocess: #3519259: Convert field template_preprocess functions in theme.inc
- pager preprocess: #3519257: Convert template_preprocess_pager()
- remaining bits in theme.inc #3518822: Convert template preprocess hooks in core/includes/theme.inc
- form.inc #3534334: Convert template_preprocess in form.inc
- views_ui #3535324: Convert template_preprocess and related functions in views_ui
- views #3535680: Convert template_preprocess in views
- system #3518903: Convert template preprocess in system.module
- node #3532204: Move preprocess functions into NodeThemeHooks
- image #3533290: Convert template_preprocess functions in image module
- update #3534288: Convert template_preprocess functions in update module
- file #3536742: Convert template_preprocess functions in file module
- block_content: deprecated by #3346394: Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider
- locale/language/search (remaining ones with an include file): #3538089: Convert remaining template_preprocess functions in module include files
- taxonomy: #3535439: Deprecate $variables['page'] in taxonomy term templates
- comment: #3547806: Convert remaining template_preprocess functions
- filter: #3547806: Convert remaining template_preprocess functions
- layout_discovery: #3547806: Convert remaining template_preprocess functions
- link: #3547806: Convert remaining template_preprocess functions
- media: #3547806: Convert remaining template_preprocess functions
- media_library: #3547806: Convert remaining template_preprocess functions
- navigation: #3547806: Convert remaining template_preprocess functions
- responsive_image: #3548326: Convert template_preprocess and helper functions in responsive_image module
- toolbar: #3547806: Convert remaining template_preprocess functions
- user: #3547806: Convert remaining template_preprocess functions
Test module that should remain procedural
- module_test_procedural_preprocess
For each create a new ${Module}ThemeHooks file and move hook theme and the template preprocess methods there.
Use git diff 11.x --color-moved=dimmed_zebra --color-moved-ws=ignore-all-space to compare moved code vs changed code.
Remaining tasks
Create child tasks.
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | template_preprocess.txt | 10.97 KB | nicxvan |
Issue fork drupal-3504381
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dwwComment #3
nicxvan commentedI have attached a list of all of the preprocess functions in core.
Comment #4
catch#3501136: Explicitly register template_preprocess callbacks in hook_theme() is in.
Comment #5
berdirAbout 110, some already converted now.
I'd prefer splitting this a bit, thoughts:
* One for remaining bits in core/includes? (32, including already convered ones)
* one for views + views_ui (about 25)
* one for system (13)
* one for the remaining ones ? (110 - 32 - 25 -13 = 40)
last chunk still seems pretty big, so maybe split out those that have 4 or more on their own (update, image, file). they all also have include files that can then be removed completely.
For modules, what I'd like to do is move their hook_theme() + the preprocess callbacks into a new ThemeHooks or ${Module}ThemeHooks, that does make it a bit bigger though, but otherwise we have to move it again.
Comment #6
nicxvan commentedI'd vote for splitting it along the 4 lines you mentioned.
Let's move them to ${Module}ThemeHooks, having files called the same is already causing issues finding the right file.
Let's hold off on splitting the last chunk until we get a look at it, but if anything obvious pops up we can split those out to a new issue pretty easily.
Comment #7
nicxvan commentedComment #8
berdirMight need to split this up into more chunks. With deprecations, reflowing of the code and all those references in templates, it's a lot of changes, already at 530 insertions(+), 314 deletions(-) and only did the part of theme.inc that I put in global ThemePreprocess, there's still field templates, pager, breadcrumb, image, menu and more.
Comment #9
nicxvan commentedYeah no objection here.
Comment #10
ghost of drupal pastGiven the standing issue about removing ModuleServiceProvider I would advise to be cautious about introducing another magic named class
Comment #12
berdirThere is no magic class name here. It's just on conventions on how hook classes are named
Comment #13
nicxvan commentedHere is where we are working out the naming convention: #3493453: [meta] Standardize and clean up hook classes in core
Comment #14
ghost of drupal pastSorry for the misunderstanding: I thought you are converting hooks by themes.
Comment #15
nicxvan commentedThat's on the roadmap but this is only about template preprocess hook after #3501136: Explicitly register template_preprocess callbacks in hook_theme() though with that change this handles all template preprocess no matter where it is defined.
Comment #16
nicxvan commentedComment #17
nicxvan commentedComment #18
berdirComment #19
berdirComment #20
nicxvan commentedComment #21
berdirUpdated summary a bit, added new issues. I've mostly split up those that have functions in include files, to unblock deprecating the 'file' key.
The big one that's left is views.module, that one is scary. the views theme hook is very complex and dynamic and it automatically defines theme hooks for its plugins, so we need to figure out how to define their template preprocess functions. Either explicit definition in the plugins or some kind of logic. Could even consider putting them on the plugin classes directly, but that would require them to be static.
Comment #22
berdirComment #23
berdirI'm a bit unsure how to deal with inc files in modules that (only) contain template preprocess functions and how to deal with them. Right now, I've moved the BC layers to .module and deleted the file. My reason for that was that it allows us to see which .inc files are really left with stuff and I think we do have a BC policy that files and where these functions are is not covered by it. I also thought that might make the BC layer more likely to work, as the .inc file wont' be autoloaded anymore, not from the original definition anyway.
However, there are also some drawbacks to it: While we claim that those inc files and location of functions aren't covered by BC, it can break things in annoying ways, such as kernel tests loading those files. It also makes the merge requests larger, not only do we copy all the function docblocks to the new OOP classes, but we also move the deprecated ones to the .module file.
In a number of cases, such as template preprocess and helper functions in views_ui, it also feels a bit silly to provide BC for all that, as those are rarely if ever called directly. So I was wondering if we should really always keep them as BC. But I guess so, to me the main advantage is that if we always do it, we don't need discussions on when it's worth it and when not, and the cost of keeping them around is pretty minor, they'll be easy to find and cleanup and we have means now to do with the merge request reviews with the zebra diff.
Any thoughts on all of this?
Comment #24
nicxvan commentedIt's tougher than it seems.
My vote is if they are the only functions, move them.
If the diff is small move them.
If we're pushing up against limits like update leave them all and let's open a follow up.
Comment #25
berdirSummary for the slack discussion with @catch and @larowlan on this (https://drupal.slack.com/archives/C079NQPQUEN/p1752472142632779):
We move the functions, but keep an empty .inc file to not break some edge cases around loadInclude() with phpstan and manual include_once/require once as done in some kernel tests.
Comment #26
nicxvan commentedViews will likely conflict with this: https://www.drupal.org/project/drupal/issues/3535943
Comment #27
kim.pepperComment #28
nicxvan commentedComment #29
berdirComment #30
nicxvan commentedHow many more after these ones?
Comment #31
berdirIt's still a good chunk of modules left, but at this point, most just have 1-3 template_preprocess function and I'm thinking about grouping them. I think I will try to do one group for all those that have a file key, so we have similar things together (like all the deprecated .inc files) and also that should then unblock #1177762: Deprecate automatic template_preprocess discovery and 'includes'/'file' support from hook_theme(). And then one other issue for the remaining ones, maybe.
Comment #32
berdirComment #33
nicxvan commentedCan we keep the git command in the summary?I use it to review each issue and having it here is handy.
Comment #34
berdirCertainly, I also dropped file, had this open in an old tab and sometimes browser remembering input of textareas is counter-productive. Restored.
Comment #35
berdirComment #36
berdirComment #37
nicxvan commentedBump to update statuses.
Comment #38
nicxvan commentedEnumerated remaining modules I saw
Comment #39
berdirPut all remaining ones except responsive image into a single issue. That one has about 4 helper functions that are only used by preprocess but are fairly large, so I thought it makes sense to do that all together, then that .module is done and it's all together.
Comment #40
nicxvan commentedGetting close!
Comment #41
berdirComment #42
nicxvan commentedI think just four issues remaining!
Comment #43
berdirThe conversion is (almost) done. The last step is just explicit deprecation: #1177762: Deprecate automatic template_preprocess discovery and 'includes'/'file' support from hook_theme()