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

Issue fork drupal-3564510

Command icon 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

roy6432 created an issue. See original summary.

ralphmoser’s picture

Prevent 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.

ressa’s picture

Title: <After updating from Drupal 11.2.10 to 11.3.0, I see a white screen with the following error: (try again later) » White screen and "try again later" error after updating from Drupal 11.2.10 to 11.3.0
Issue summary: View changes

Thanks 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...

cilefen’s picture

Issue tags: -core, -ThemeRegistry, -Return value, -Claro theme +Needs steps to reproduce

What is the root cause?

ralphmoser’s picture

It 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.

nicxvan’s picture

Can you share a list of modules you have installed?

nicxvan’s picture

Component: Claro theme » theme system
ralphmoser’s picture

StatusFileSize
new5.06 KB

Here's my composer file.

nicxvan’s picture

Do 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.

nicxvan’s picture

Looking 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.

nicxvan’s picture

@Berdir suggested a hook_theme_registry_alter might do this, can you review your site to see if there are any of those?

ralphmoser’s picture

I 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):

/**
 * Implements hook_theme_registry_alter().
 */
#[LegacyHook]
function ting_theme_registry_alter(&$theme_registry): void {
  \Drupal::service(TingWebformHooks::class)->alterThemeRegistry($theme_registry);
}

Function in TingWebformHooks class:

  #[Hook('theme_registry_alter')]
  public function alterThemeRegistry(&$themeRegistry): void {
    $path = $this->pathResolver->getPath('module', 'ting');
    $themeRegistry['webform_submission_form']['path'] = $path . '/templates';
    $themeRegistry['webform_section']['path'] = $path . '/templates';
    $themeRegistry['webform_confirmation']['path'] = $path . '/templates';
  }

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?

nicxvan’s picture

Thank you, that looks fine at first glance. Yes the Gin refactor is likely a coincidence since global preprocess is module only.

ralphmoser’s picture

Remark:
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.

nicxvan’s picture

Yes 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.

nicxvan’s picture

Status: Active » Needs review
ralphmoser’s picture

Agree with getPreprocessInvokes fix. Thanks for the merge request.

smustgrave’s picture

Version: 11.3.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for reporting, possible to get concrete steps added to the summary to reproduce.

Also may need test coverage for this.

cilefen’s picture

Title: White screen and "try again later" error after updating from Drupal 11.2.10 to 11.3.0 » TypeError: Drupal\Core\Utility\ThemeRegistry::getGlobalPreprocess(): Return value must be of type array

Let's make this easier to find.

catch’s picture

Should 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.

nicxvan’s picture

I 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.

berdir’s picture

This 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.

serge_teodori’s picture

Hello a change between 11.2.10 and 11.3.0 introduced the error. Here a diff output:

179c179
<   public function getPreprocessInvokes() {
---
>   public function getPreprocessInvokes(): array {
180a181,193
>   }
> 
>   /**
>    * Gets global preprocess callbacks.
>    *
>    * @return array
>    *   An array of preprocess callbacks that should be called for every theme
>    *   hook.
>    *
>    * @internal
>    */
>   public function getGlobalPreprocess(): array {
>     return $this->get('global preprocess');

Solved temporarly by rmoving the : array

nicxvan’s picture

Somehow 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.

nicxvan’s picture

nicxvan’s picture

Version: 11.x-dev » main
Assigned: roy6432 » Unassigned

This 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

nicxvan changed the visibility of the branch 11.x to hidden.

nicxvan changed the visibility of the branch 3564510-white-screen-and to hidden.

nicxvan changed the visibility of the branch main to hidden.

nicxvan’s picture

Status: Needs work » Needs review

Ok that was fun(tm)

berdir’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs steps to reproduce, -Needs issue summary update

I 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.

  • catch committed a61ea9fb on 11.x
    fix: #3564510 TypeError: Drupal\Core\Utility\ThemeRegistry::...

  • catch committed 5d5b25bd on main
    fix: #3564510 TypeError: Drupal\Core\Utility\ThemeRegistry::...
catch’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main, 11.x and 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 5e8250b2 on 11.3.x
    fix: #3564510 TypeError: Drupal\Core\Utility\ThemeRegistry::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.