Problem/Motivation
The following functions should be moved into NodeThemeHooks:
template_preprocess_node_add_list
node_preprocess_html
node_preprocess_block
node_theme_suggestions_node
template_preprocess_node
Following these CRS:
https://www.drupal.org/node/3504125
https://www.drupal.org/node/3496491
Proposed resolution
Move hooks to NodeThemeHooks
Move NodeHooks1::theme to NodeThemeHooks
Remaining tasks
Do it
Postponed on #3524738: Fatal error when passing NULL to Renderer::render()
Review
| Comment | File | Size | Author |
|---|
Issue fork drupal-3532204
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:
- 3532204-move-preprocess-functions
changes, plain diff MR !12475
Comments
Comment #2
acbramley commentedComment #4
acbramley commentedComment #5
mstrelan commentedI compared the changes from node.module to NodeThemeHooks with the following commands:
Then looking at node-theme-hooks.patch, which I've attached, I can see the only changes are:
I also grepped for each of the removed functions in case there were string references in comments and found 26 in 11.x and 4 in this branch.
So the following will need to be updated:
Comment #6
acbramley commentedThanks @mstrelan!
The
node_preprocess_htmlcomment is legit, I'll fix that.The other ones are actually just example documentation of these hooks. That whole thing needs an update because it says things like "Implementations of this hook must be placed in *.module or *.theme files", and IMO should not use core modules as examples but that's of course for another issue.
The line about node_theme_suggestions_node is just describing how these suggestions are called, not specifically referencing node's implementation of the hook.
Comment #7
mstrelan commentedGreat. I also checked that all of the services injected in to the new class have been used. I found another issue that had injected services but not used them, our phpstan config doesn't detect that. This is RTBC as per #5 and #6.
Comment #8
acbramley commentedCreated #3532211: theme.api.php needs updates now that hooks can be OO for the docs issues.
Comment #9
nicxvan commentedThese are the last hooks you can add the container parameter.
Comment #10
acbramley commentedHmm adding back the old functions has broken tests in weird ways
Call to a member function getOwnerId() on nullComment #11
acbramley commentedTurns out it was the procedural hook skip that caused the failures.
@nicxvan any idea what hook is remaining that's causing that? I can't see any
Comment #12
nicxvan commentedThis is ready again.
I confirmed the template preprocess are deprecated now. There are literally no uses in contrib for it and we don't have to technically deprecate them, but since people do occasionally call them we've been deprecating template preprocess.
I spent over an hour trying to figure out why marking node as converted breaks
core/modules/jsonapi/tests/src/Functional/UserTest.phpand another jsonapi test.I followed these principles:
None of these provided a hint.
I even grabbed every function in the three files removed node and grepped for something calling modulehandler invoke with the function name and nothing came back beyond node_mass_update which isn't a real hook.
hook_node_grants is INVOKED by some of the functions, but that shouldn't matter.
I think we move marking this to a follow up.
Comment #13
berdirOh, a challenge, can't resist a challenge.
It's user cancel, so I assumed it's related to the user_cancel hook in node module and from there it was pretty straight forward to identify.
\Drupal\node\Hook\NodeHooks::userCancelBlockUnpublish uses ModuleHandler::invoke() to call node_mass_update. that's not a hook, but it misuses that to load the function in the include file.
This works:
Agreed that this is out of scope, but lets open an issue for it. There is a risk that we break similar calls though.
Comment #14
acbramley commentedCrediting you both for the sleuthing, I'll open the issue
Comment #15
acbramley commentedCrediting @mstrelan for the excellent review in #5
Comment #16
acbramley commented#3533083: Move node_mass_update_* functions to service and fix invalid hook invocation in NodeHooks for #13
Comment #17
nicxvan commentedOh of course that is why the attribute worked cause I moved it to the module file to make changing position easier.
Btw there is a duplicate about investigating mass_update.
Comment #18
berdir#3524738: Fatal error when passing NULL to Renderer::render() isn't RTBC yet, but I'd suggest we hold this until that's in as that will need to be backported and having template_preprocess_node() converted to OOP will complicate that.
Comment #19
acbramley commentedMakes sense
Comment #20
nicxvan commentedBlocker just got in.
Comment #21
acbramley commentedRebased (badly), but this should be ready for re-review.
Comment #22
nicxvan commentedWe're missing the trigger error deprecations in the template functions.
Here are the snippets, suggestions are not working for me right now.
Comment #23
acbramley commentedClearly did this too early on a monday. Thanks for the snippets @nicxvan
Comment #24
nicxvan commentedDidn't mention this in 22, but I reviewed this from scratch there, confirmed all deprecations are correct which is how I caught the missing trigger_error.
Checked all usages align properly
Checked all conversions are correct.
Comment #25
catchCommitted/pushed to 11.x, thanks!
Comment #26
catchComment #29
catch