Convert theme hooks (defined by hook_theme()) to be objects

Created on 24 March 2017, over 7 years ago
Updated 11 September 2023, 10 months ago

Problem/Motivation

There have been multiple issues lately involving the theme registry.
Because the theme hook arrays are passed around to many places, it is very difficult to track down which code is modifying which key.
It is also hard to full understand the ways that certain keys interact together.

This is very similar to the issues with the $form_state arrays in D7 and before.

Proposed resolution

Mimic the same solution used for $form_state: create a class to hold these theme hooks.
This time, we'll need full BC.

Remaining tasks

- review
- commit
- open follow-up #2873117: Remove ArrayAccess from ThemeHook

User interface changes

N/A

API changes

API addition and deprecation, no breaking changes
hook_theme() should now return an array of \Drupal\Core\Theme\ThemeHook objects
ThemeHook implements ArrayAccess for BC purposes.

Data model changes

N/A

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Theme 

Last updated about 17 hours ago

Created by

🇺🇸United States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

  • Needs performance review

    It is used to alert the performance topic maintainer(s) that an issue significantly affects (or has the potential to affect) the performance of Drupal, and their signoff is needed. See the governance policy draft and Drupal Core gate - performance for more information.

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇫🇷France andypost

    Starting with #129 the patch after re-roll became x2 smaller

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Custom Commands Failed
  • 🇮🇳India sourabhjain

    Trying to fix to custom command failed issue of #132

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Removing credit for #134, 131, 130, 129, 123, 122 as it is expected to check a patch before uploading. You can check for build errors make sure to run ./core/scripts/dev/commit-code-check.sh before uploading a patch to make sure there are no issues with code formatting. see https://www.drupal.org/docs/develop/development-tools/running-core-devel...

    Hiding those patches as well.

    This was previously tagged for issue summary update which still needs to happen.

    Also as @andypost pointed out the patch got cut in half. How come?

  • Assigned to tim.plunkett
  • 🇺🇸United States tim.plunkett Philadelphia

    The entire ThemeHook.php was dropped from the patches. Working on this.

  • 🇺🇸United States tim.plunkett Philadelphia

    Switched to an MR.
    This will probably break things, leaving assigned for now.

    Fixed a bunch of credit.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,356 pass, 8 fail
  • @timplunkett opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    106 pass, 3,733 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,379 pass
  • last update 12 months ago
    29,444 pass
  • last update 12 months ago
    29,812 pass
  • Status changed to Needs review 12 months ago
  • 🇫🇮Finland lauriii Finland

    Tried to rebase the MR. Needs performance testing still.

  • 🇩🇪Germany donquixote

    Needs performance testing still.

    Just a quick note not for performance but memory/storage.

    I was suspecting that these objects significantly increase the size of the registry when serialized in cache, due to all the unused properties.
    But actually, uninitialized properties take zero space when serialized: https://3v4l.org/eoLeo

    Therefore the increase in cache space is much smaller than I previously expected, at least for plain core.
    For me, the string length in the `cache_default` table grows from ~83.000 to ~100.000 for theme_registry:olivero.

  • 🇫🇷France andypost

    It's getting bigger just because of namespaced class but as I see it has \0 code so sqlite truncating it

    /var/www/html/web $ drush sqlq "select * from cache_default where cid like 'theme_registry%';"
    theme_registry:build:modules|a:147:{s:26:"big_pipe_interface_preview";O:27:"Drupal\Core\Theme\ThemeHook":7:{s:7:"|-1|1690406986.891|1||0
    theme_registry:claro|a:177:{s:26:"big_pipe_interface_preview";O:27:"Drupal\Core\Theme\ThemeHook":7:{s:7:"|-1|1690406986.915|1||0
    theme_registry:olivero|a:181:{s:26:"big_pipe_interface_preview";O:27:"Drupal\Core\Theme\ThemeHook":7:{s:7:"|-1|1690406989.703|1||0
    

    my numbers

    /var/www/html/web $ drush sql:query "select cid, length(cast(data as blob)) from cache_default where cid like 'theme_registry%';"
    theme_registry:build:modules|74958
    theme_registry:claro|99383
    theme_registry:olivero|99111
    
    /var/www/html/web $ drush sql:query 'delete from cache_default;'
    
    ... removing patch
    
    /var/www/html/web $ drush sql:query "select cid, length(cast(data as blob)) from cache_default where cid like 'theme_registry%';"
    theme_registry:build:modules|61296
    theme_registry:claro|82337
    theme_registry:olivero|82029
    
  • Issue was unassigned.
  • 🇺🇸United States tim.plunkett Philadelphia
  • Status changed to Needs work 11 months ago
  • The 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 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.

  • last update 10 months ago
    Custom Commands Failed
  • Status changed to Needs review 10 months ago
  • Status changed to Needs work 10 months ago
  • 🇺🇸United States smustgrave

    Seems rebase had some errors.

Production build 0.69.0 2024