Problem/Motivation
11.1 excluded hook_preprocess and hook_preprocess_HOOK from OOP and threw an exception when one was added using a Hook attribute.
11.2 adds support for both of these hooks.
We need to remove the logic exception from 11.1 so that contrib can support both. We should trigger a message when the OOP equivalent is used with no corresponding procedural implementation to ensure the hooks run.
https://www.drupal.org/project/drupal/issues/3523109
Steps to reproduce
Proposed resolution
No longer prevent preprocess.
Set error if the procedural hook is missing
Remaining tasks
Update CR with minimum 11.1 version once this is in: https://www.drupal.org/node/3496491
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3524716-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-3524716
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:
- 3524716-11.1-update-gather
changes, plain diff MR !12136
Comments
Comment #2
catchOne possible idea, it's quite horrible.
Instead of the exception, can we reverse engineer what the expected function name would be from the OOP hook implementation, check function_exists(), and if it's not there, trigger_error() something?
Comment #4
nicxvan commentedI'm not sure why this is failling:
core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php fails cause it's looking for modules as themes and they don't exist.
This test doesn't run locally so I can't easily debug.
Comment #5
nicxvan commentedFor some reason this change is triggering module handler to not have the modules when LibraryDiscoveryParser::buildByExtension is checking so it checks for modules as themes.
This doesn't make sense, this shouldn't change anything related to this.
I even tried an alternate version where we pass the module in through collect by attribute to procedural check and throw the error only there if the function doesn't exist.
I reverted my changes and it still fails. Is this an 11.1.x only failure?
Comment #6
nicxvan commentedThat test is busted on 11.1.x: https://git.drupalcode.org/project/drupal/-/pipelines/499192
Comment #7
nicxvan commentedI added a test for this specifically, but even with the expect exception for the one we expect, I'm getting a symfony exception.
I could use some assistance getting past this:
Comment #8
nicxvan commentedI converted to trigger_error as suggested in 2. There doesn't seem to be a way to assert user warnings anymore. I tried converting to an exception in the test as suggested by the phpunit issue, but I run into the same symfony exception.
Comment #9
nicxvan commentedThis is truly ready for review now!
Please credit @fathershawn for his help on slack getting me past the test issues!
The failure is unrelate I think and exists on 11.1.x HEAD.
Comment #10
nicxvan commentedCreated #3525090: [11.1] ResolvedLibraryDefinitionsFilesMatchTest is failing for the failing test on 11.1.x HEAD
Comment #11
nicxvan commentedComment #12
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #13
nicxvan commentedI think the bot is wrong here cause it's a different branch.
Comment #14
nicxvan commentedComment #15
nicxvan commentedComment #16
catchThis looks great.
Currently, if you add an OOP preprocess hook, you get an exception on 11.1 because it doesn't support preprocess has OOP hooks, and it's trying to stop you prematurely converting things that won't work.
With the MR, the next 11.1 patch release will allow the OOP hook to exist and ignore it, as long as there's a procedural version too - e.g. still using
LegacyHook, but warn you if the legacy hook is missing.The result is that modules will be able to require >= 10.4.0 | >= 11.1.8 (or whatever exact version it ends up in) if they want to convert. Otherwise their only option would be >= 10.4.0 | > 11.2.0
Comment #17
alexpottCommitted 59f1bee and pushed to 11.1.x. Thanks!
Comment #19
alexpottComment #20
nicxvan commentedI updated the CR in https://www.drupal.org/node/3496491
Comment #22
nicxvan commented