Phase out Drupal\Core\Template\Loader\ThemeRegistryLoader

Created on 1 June 2020, over 4 years ago
Updated 29 March 2023, over 1 year ago

Problem/Motivation

Drupal\Core\Template\Loader\ThemeRegistryLoader is a Twig Loader that allows referencing to Twig templates based on Drupal template inheritance rules. This comes with some great benefits because of the flexibility it provides. However, the flexibility comes with lots of complexity. This approach is also prone to errors.

For example, core/themes/classy/templates/block/block--local-tasks-block.html.twig is extending block.html.twig template from the theme registry. When someone wants to override block.html.twig in a subtheme of Classy, it is necessary to keep in mind all of the potential ways the template could be extended to not break any templates extending the template. In this use case, block--local-tasks-block.html.twig is overriding content block, meaning that the site will break if the block gets removed in an overriding template.

Proposed resolution

Replace usages of Drupal\Core\Template\Loader\ThemeRegistryLoader with calls that use Twig namespaces.

For example, we should change core/themes/classy/templates/block/block--local-tasks-block.html.twig from referring block.html.twig to referring {% extends "@classy/block/block.html.twig" %}.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Needs work

Version

10.1

Component
Theme 

Last updated 1 day ago

Created by

🇫🇮Finland lauriii Finland

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.

  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands

    Patch from #20 failed because of these 4 files:

    core/profiles/demo_umami/themes/umami/templates/classy/block/block.html.twig
    core/profiles/demo_umami/themes/umami/templates/classy/media-library/links--media-library-menu.html.twig
    core/themes/claro/templates/classy/block/block.html.twig
    core/themes/claro/templates/classy/media-library/links--media-library-menu.html.twig

    New D10 only patch. Don't know why but a interdiff didn't work

  • Status changed to Needs review over 1 year ago
  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    How come we are leaving out those changes to claro and demo_umami?

  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands

    I think those files are removed because of #10 / #11:

    I discussed this with lauriii. Because of the way the inheritance works, the changes to classy/stable/stable9 would be BC breaking, so those won't be updated. I was correct that the links templates were mistakenly absent, so leaving those in the patch. Also, the references to @block/block will be fixed here. All the themes should only be referencing templates they contain.

  • 🇺🇸United States smustgrave

    Gotcha. There is a valid test failure in the patch also. First failure may be random but the second seems valid

  • 🇫🇷France andypost

    yes, failure in Drupal\KernelTests\Config\DefaultConfigTest is valid

Production build 0.71.5 2024