Problem/Motivation

This is the core of #3525011: Allow complete replacement of the default theme engine (twig) in Drupal core. ThemeManager::render() (line 348) hardcodes:

if ($info['type'] != 'module') {
  $theme_engine = $active_theme->getEngine();
}
else {
  $theme_engine = 'twig';
}

Every module-provided template — most of what core renders — goes to Twig regardless of the active engine. Separately, Registry::build()'s docblock has documented an engine key on theme hook info since the D8 cycle, but processExtension() never writes it.

Steps to reproduce

Install a theme using a non-Twig engine (e.g. nyan_cat) as default. A hook declared by a module, not overridden by the theme, still renders through Twig even when the active engine could provide it.

Proposed resolution

Depends on #3625132: Add a template ownership interface so theme engines can tell core which templates they provide (TemplateOwnershipInterface). Populate $result[$hook]['engine'] in Registry::processExtension(). Replace the hardcoded branch in ThemeManager::render() with negotiated dispatch:

$theme_engine = $info['engine'] ?? $this->negotiateEngine($info, $template_file, $active_theme);

negotiateEngine() checks whether the active engine implements TemplateOwnershipInterface and provides the template via hasTemplate(); falls back to Twig otherwise. Registry caching means hasTemplate() runs at cache-rebuild time, not per render.

Remaining tasks

  • Implement registry recording and negotiated dispatch
  • Kernel test: a module-declared hook the active engine provides renders through it; one it doesn't provide still renders through Twig, same request
  • Performance test asserting zero hasTemplate() calls on a warm-cache render
  • Confirm whether an update hook is needed for the registry cache shape change

User interface changes

None.

Introduced terminology

None.

API changes

theme.registry hook info gains a populated engine key. No BC break: existing sites resolve to 'twig' in every case that reaches Twig today.

Data model changes

Cached registry entry shape changes (new key). Rebuilt on cache clear; no schema change.

Release notes snippet

Theme engines can now render module-provided templates they declare support for, instead of those always falling back to Twig.

Comments

matthand created an issue. See original summary.

matthand’s picture

Issue summary: View changes
matthand’s picture

Status: Active » Postponed

Postponing while we build consensus on the plan in parent issue.