Deprecate theme_get_registry()

Created on 18 March 2023, over 1 year ago
Updated 28 March 2023, about 1 year ago

Problem/Motivation

There's no usage in core (except hook example) and few in contrib http://codcontrib.hank.vps-private.net/search?text=theme_get_registry&fi...

Steps to reproduce

$ git grep theme_get_registry
core/includes/theme.inc:91:function theme_get_registry($complete = TRUE) {
core/lib/Drupal/Core/Render/theme.api.php:550:    $hooks = theme_get_registry();

Proposed resolution

deprecate the function

Remaining tasks

- https://www.drupal.org/node/3348850 →
- patch and test
- review/commit

User interface changes

no

API changes

function theme_get_registry() is deprecated

Data model changes

no

Release notes snippet

📌 Task
Status

Fixed

Version

10.1 ✨

Component
Theme  →

Last updated about 5 hours ago

Created by

🇫🇷France andypost

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

Comments & Activities

  • Issue created by @andypost
  • Status changed to Needs review over 1 year ago
  • 🇫🇷France andypost

    Here's a CR and patch

  • 🇫🇷France andypost

    fix CS

  • Status changed to RTBC over 1 year ago
  • 🇳🇱Netherlands daffie

    All code changes look good to me.
    Deprecation message testing has been added.
    The testbot return green.
    The IS and the CR are in order.
    For me it is RTBC.

  • 🇦🇺Australia Purencool

    The result of testing patch 3348848-3.patch.

    Branch

     git branch                                                                          
      10.0.x
    * 10.1.x
    

    Searching references of the theme_get_registry function being called before applying the patch.

     git grep theme_get_registry                                                         
    core/includes/theme.inc:function theme_get_registry($complete = TRUE) {
    core/lib/Drupal/Core/Render/theme.api.php:    $hooks = theme_get_registry();
    

    When administering the patch the following error occurred. The issue is likely the testLegacyThemeRegistryRebuild() method was added to core.

     git apply --index 3348848-3.patch                                                   
    error: patch failed: core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:256
    error: core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php: patch does not apply
    
    @@ -256,4 +256,18 @@ public function testThemeTemplatesRegisteredByModules() {
         $this->assertEquals($expected, array_values($registry['theme_test_registered_by_module']['preprocess functions']));
       }
    

    Using @andypost's original code a refactored patch was created and has been added to the ticket.

    www-data@5e92f19c6122:/app/build/core$ ../vendor/bin/phpunit --filter=testLegacyThemeGetRegistry ../core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php                                                                                             
    PHPUnit 9.6.5 by Sebastian Bergmann and contributors.
    
    Testing Drupal\KernelTests\Core\Theme\RegistryTest
    .                                                                   1 / 1 (100%)
    
    Time: 00:01.550, Memory: 8.00 MB
    
    OK (1 test, 4 assertions)
    
    

    After the newly created patch the theme_get_registry function seems to be no longer called.

    www-data@5e92f19c6122:/app/build$ git grep theme_get_registry                                                                
    core/includes/theme.inc:function theme_get_registry($complete = TRUE) {
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:   * Tests deprecated theme_get_registry function.
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:   * @see theme_get_registry()
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:    $this->expectDeprecation('theme_get_registry() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method get() instead. See https://www.drupal.org/node/3348850');
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:    $this->assertEquals($registry->get(), theme_get_registry());
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:    $this->expectDeprecation('theme_get_registry() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service method getRuntime() instead. See https://www.drupal.org/node/3348850');
    core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php:    $this->assertEquals($registry->getRuntime(), theme_get_registry(FALSE));
    
  • Status changed to Fixed about 1 year ago
  • 🇫🇮Finland lauriii Finland

    Committed e228020 and pushed to 10.1.x. Thanks!

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

Production build 0.69.0 2024