Some parts of Theme\Registry are written as if they support multiple themes

Created on 31 March 2018, over 6 years ago
Updated 3 May 2023, over 1 year ago

Drupal\Core\Theme\Registry usually works like this:

  • In the constructor, $theme_name is NULL.
  • When first needed, Registry->init() is called with $this->themeName, which at this time is NULL.
  • This fills $this->theme with the current theme, whereas $this->themeName is still NULL.
  • Later, $this->registry[$this->theme->getName()] may be filled with theme registry entries for the current theme.
  • Later, $this->runtimeRegistry[$this->theme->getName()] may be filled with the runtime registry for the current theme.
  • There is no situation where $this->theme or $this->themeName or the result of $this->theme->getName() would be changed after its first initialization.
    (at least I found none)
    And if it would happen, it would probably break things.

Proposed change

We should remove all artifacts that suggest that Theme\Registry would support more than one theme:

  • $this->registry[$theme_name] becomes $this->registry.
  • $this->runtimeRegistry[$theme_name] becomes $this->runtimeRegistry.
  • $this->themeName should be initialized in $this->init().
  • The parameter $theme_name in $this->init() is redundant, and should be removed.

Follow-up

In a follow-up issue, we could make a proxy split, like so:

One class where $theme_name and $theme object are passed into the constructor.
This will contain most of the logic.
In this class we no longer need to worry about whether it has been initialized or not.

Another class which acts as a proxy layer, and which lazily creates the "real thing" when it is needed.

📌 Task
Status

Active

Version

10.1

Component
Theme 

Last updated 1 day ago

Created by

🇩🇪Germany donquixote

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France andypost

    There's a case when at least 2 themes are required - when you collect layouts from frontend (default theme) to display them as list at "manage display" pages (in admin theme)

Production build 0.71.5 2024