Problem/Motivation
This is a follow-up on #3544715: Add oop support to hooks currently supported by themes and was determined in the Gin 6.x branch in preparation to being merged into core.
In src/Hook/PreprocessHooks.php there are next to others, these hook implementations:
preprocess_linkspreprocess_links__action_linkspreprocess_links__dropbuttonpreprocess_links__media_library_menu
Three of them are recognized, but not preprocess_links__action_links. It turns out, that this hook is being found and registered, but with the type module and not type theme like the other 3.
When we add a template links--action-links.html.twig to Gin, then it gets recognized correctly with the type theme.
Is that on purpose and do we have to have templates for each preprocess hook in a theme, even if that template doesn't do anything other than {% extends "links.html.twig" %} in this case?
Or is there a better way around this.
Steps to reproduce
Proposed resolution
We can add type in the respective collectors:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
Then use that in Registry to assign the appropriate mapping.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
Remaining tasks
Review
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3556794-13.diff | 7.37 KB | herved |
Issue fork drupal-3556794
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:
- 3556794-preprocesshookcandidates-in-themes
changes, plain diff MR !13724
Comments
Comment #2
nicxvan commentedI think there is something in:
That needs updating.
The hooks are correctly discovered, we may need to split the preprocess for suggestions for mapping.
Comment #3
nicxvan commentedOr we add a type to the suggestions and use that...
Comment #4
nicxvan commentedComment #6
nicxvan commentedAt least a major, but probably critical.
I think this is ready for review assuming the tests pass.
Comment #7
nicxvan commentedComment #8
nicxvan commented@berdir pointed out there are multiple workarounds for this (add the template, implement the base hook and check variable state)
Also this exists in 10.x
We should still address this and figure out a better test, but this can remain normal.
Comment #9
berdirNeeds work to implement the test we discussed.
Comment #10
berdirI pushed more explicit test coverage, didn't remove yours yet. We can build on the existing preprocess and the existing test for this and don't need to add more stuff.
Note that the assertStringContainsString() does not yet fail in HEAD, because it still works as a function as it goes through ModuleHandler::legacyInvoke() as invoke() falls back to that in case the listener isn't known. I wasn't sure if and how much existing explicit test coverage we have and fails in our bulk conversion issue, but I thought it makes sense to make this explicit in this scope, should be easier to debug in the future as we refactor things.
The trick is making it the active theme, because right now we just install it and don't make it active, so we can't render with it.
The nice side effect that I didn't include here yet is that this makes the weird constructor argument stuff for Registry unnecessary. Setting the active theme means we can just do
$registry_theme = \Drupal::service(Registry::class);and the constructor and manual setThemeManager call and just use as a service like any other and it will get the theme through the theme manager as regular requests. Then we no longer execute a different code path just for those tests. I think we want to do this cleanup as part of cleaning up the Registry constructor, we can also drop the root parameter in D12 and then we can reshuffle the whole thing (with BC)Comment #11
nicxvan commentedAh that makes sense, and that cleanup sounds great, I can create an issue to track that in a bit.
I think your test looks good, but I want to review it closer in a bit.
These are the tests that had failures related to this fix:
Comment #12
herved commentedI just stumbled on this, from a custom subtheme of ui_suite_bootstrap and some hooks such as
The MR seems to solve it.
Comment #13
herved commentedCurrent MR snapshot
Comment #14
ambient.impactCan confirm the merge request fixes this in the theme I'm working on, thanks! Will this fix will make it into the next patch release of 11.3.x? I realize it can worked around but it was also really difficult to track down what was going wrong on my end, so I can imagine there are likely a good number of people getting bit by this. Regardless, thanks for the fix!
Comment #15
nicxvan commentedI think this is ready for review of you want to take a pass.
I did the actual fix so I can't mark it myself.
Test only fails as expected, I have not reviewed @berdir's tests super closely yet.
Comment #16
berdir@nicxvan I think with the new RTBC rules, it's perfectly valid if I review your fix and you review the test coverage. If you check my feedback and remove the extra test coverage and review my test then I'm OK with setting this to RTBC afterwards.
Comment #17
nicxvan commentedYes, I reviewed your test now, it's much cleaner and more resilient than what I was doing.
I've removed my tests.
I think the fix is ready for review.
Comment #18
berdirReviewed.
Comment #19
nicxvan commentedI addressed your feedback!
Comment #20
berdirThanks, I think this makes much easier to understand what we do there. As mentioned before, I think I can RTBC this, since I haven't touched the implementation changes while you have reviewed the tests I wrote for it.
Not sure about priority here. I think wasn't clear on my 10.x comment back then in slack. This is definitely a new bug, what I experienced in 10.x was something else that is also related to preprocess for theme suggestions, but is different. This is definitely a regression and probably could be seen as major.
Comment #21
nicxvan commentedThis is also blocking: #3560851: Convert test_theme to OOP
Comment #22
nicxvan commentedForgot I didn't bump this back to major after looking at 20 and 6
Comment #23
larowlanOne minor issue I spotted
Comment #24
nicxvan commentedI've addressed your feedback! Thanks!
Comment #29
larowlanCommitted to main and backported to 11.x and 11.3.x
Thanks folks