Problem/Motivation
After updating from Drupal 11.2.10 to 11.3.0, I see a white screen with the following error: (try again later)
The following error appears in the log.
TypeError: Drupal\Core\Utility\ThemeRegistry::getGlobalPreprocess(): Return value must be of type array, null returned in Drupal\Core\Utility\ThemeRegistry->getGlobalPreprocess() (line 193 of /var/www/vhosts/sparrowhouse.nl/httpdocs/core/lib/Drupal/Core/Utility/ThemeRegistry.php).
Steps to reproduce
Unknown: #3568066: Investigate how global preprocess map can be null
The working assumption is that a theme registry alter breaks something about the structure we pass in.
Proposed resolution
Add default return value if for some reason the array key is missing.
Remaining tasks
Confirm whether 21 is feasible (See 25)
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | composer.json_.txt | 5.06 KB | ralphmoser |
Issue fork drupal-3564510
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
ralphmoser commentedPrevent a NULL return value in the function Drupal\Core\Utility\ThemeRegistry->getGlobalPreprocess() that always has to return an array.
If the Gin-theme (based on Claro) is used as admin theme, the above error occurs in Drupal 11.3.
The following patch solves the problem.
Comment #3
ressaThanks for the issue and a patch, maybe you can create a GitLab MR? https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr...
Comment #4
cilefen commentedWhat is the root cause?
Comment #5
ralphmoser commentedIt seems that some preprocess functions of the Gin theme are not registered at all, because the get('global preprocess') function returns NULL. See also the work in progress in the linked issue.
Comment #6
nicxvan commentedCan you share a list of modules you have installed?
Comment #7
nicxvan commentedComment #8
ralphmoser commentedHere's my composer file.
Comment #9
nicxvan commentedDo you have the contextual module disabled?
The interesting thing is that getGlobalPreprocess only gets module hook_preprocess implementations.
I think it's a simple quick fix to do what you proposed, but it's interesting we're hitting that situation.
Comment #10
nicxvan commentedLooking again there is something else going on, we set the default to an empty array where it gets set, is there more to the error you are receiving?
I can push it up to see if any tests fail with this addition, but I'd like to see where it's coming from.
Comment #12
nicxvan commented@Berdir suggested a hook_theme_registry_alter might do this, can you review your site to see if there are any of those?
Comment #13
ralphmoser commentedI have two hook_theme_registry_alter functions in my code, both are just overriding the path of some templates, which are newly defined in my modules.
Function in ting module (already converted to OO code):
Function in TingWebformHooks class:
But my guess is, that the gin theme has been heavily refactored in October. And there was also work in the area of turning preprocess hooks into OO code (see Issue https://www.drupal.org/project/gin/issues/3553537). Coincidence?
Comment #14
nicxvan commentedThank you, that looks fine at first glance. Yes the Gin refactor is likely a coincidence since global preprocess is module only.
Comment #15
ralphmoser commentedRemark:
Because the ThemeRegistry::get() function can return NULL, my change in the ThemeRegistry::getGlobalPreprocess() function is mandatory, because an array as return value is requested.
Comment #16
nicxvan commentedYes that's why I added the MR, honestly we should do the same for getPreprocessInvokes.
I think this qualifies for the fix without tests policy.
I just wanted to understand better how we get into this situation to see if there is a deeper issue.
Comment #17
nicxvan commentedComment #18
ralphmoser commentedAgree with getPreprocessInvokes fix. Thanks for the merge request.
Comment #19
smustgrave commentedThanks for reporting, possible to get concrete steps added to the summary to reproduce.
Also may need test coverage for this.
Comment #20
cilefen commentedLet's make this easier to find.
Comment #21
catchShould the default to array be done in ::resolveCacheMiss()? It would mean everything else could guarantee it gets an array back, but it might be too much.
Comment #22
nicxvan commentedI got confirmation from @catch in slack that this is eligible for being fixed without tests https://www.drupal.org/about/core/policies/core-change-policies/core-gat...
Still needs an issue summary update with more detail and a followup to figure out how this is happening. Leaving need work for that.
Comment #23
berdirThis was only reported for getGlobalPreprocess(), not the other one. Seems extremely unlikely that the invokes is completely empty?
Per #12, I suspect this, especially doing it to the invokes method would hide a major issue and make all OOP preproccess hooks non-functional and therefore lots of really weird errors.
Comment #24
serge_teodori commentedHello a change between 11.2.10 and 11.3.0 introduced the error. Here a diff output:
Solved temporarly by rmoving the : array
Comment #25
nicxvan commentedSomehow I missed 21, I don't know how we would do it in resolveCacheMiss how do we know the expected type?
I don't have a super strong opinion about 23, but I trust @berdir's instincts.
I will remove the extra one in invoke I added and create the investigation follow up.
Once tests are done I think this will be ready.
Comment #26
nicxvan commentedCreated: #3568066: Investigate how global preprocess map can be null
Comment #27
nicxvan commentedThis needs to be recreated on the new main branch it was created on 11.3.x
Edit: unfortunately it looks like we need to manually update the fork. Once that is done we need to add
?? []To the getGlobalPreprocess method in ThemeRegistry
Comment #33
nicxvan commentedOk that was fun(tm)
Comment #34
berdirI think it's OK to get it in like this without test coverage, steps to reproduce are not entirely clear, but this stops the bleeding. The whole theme registry structure and build process is due for a refactor once all the BC layers are gone.
Comment #38
catchCommitted/pushed to main, 11.x and 11.3.x, thanks!