Problem/Motivation

Part of #3525011: Allow complete replacement of the default theme engine (twig) in Drupal core. Two newer core subsystems render through inline_template, so their markup cannot be overridden by any theme or theme engine:

  • Icon — Icon.php passes $icon->getTemplate() to inline_template. The template is a Twig string defined in each icon pack's *.icons.yml (template: key).
  • HTMX — HtmxRenderer::renderResponse() builds its whole <!doctype html> envelope as an inline_template. Normal pages, by contrast, go through #type => 'html' and the overridable html theme hook.

Steps to reproduce

Try to change the markup of an icon from the navigation icon pack, or of an HTMX response envelope, from a theme. Neither has a theme hook or template to override.

Proposed resolution

Icon: add an icon theme hook with the context Icon already assembles (source, content, attributes, settings, pack id). The default Twig implementation renders the pack's template: string exactly as today, so pack YAML stays unchanged and output is identical. A theme or alternative engine can then provide icon (or icon__PACK_ID via suggestions) itself.

HTMX: add an htmx_response theme hook with an htmx-response.html.twig template in the system module, mirroring how HtmlRenderer uses the html hook. The CSS/JS placeholder tokens stay in the template; HtmlResponseAttachmentsProcessor is unaffected.

Both depend on #3625133: Record the resolving theme engine in the registry and stop hardcoding Twig for module templates, not on any inline_template abstraction: once module templates negotiate their engine, these hooks fall back to Twig by default and cost alternative engines nothing.

Remaining tasks

  • Add the icon hook and suggestions; move the inline_template call into its default Twig implementation
  • Add the htmx_response hook and template
  • Confirm existing Icon and HTMX tests pass with byte-identical output

User interface changes

None. Output is identical by default.

Introduced terminology

None.

API changes

New icon and htmx_response theme hooks. No changes to icon pack definitions or the HTMX API.

Data model changes

None.

Release notes snippet

Icons and HTMX responses now render through overridable theme hooks, so themes can customize their markup.

Comments

matthand created an issue. See original summary.

matthand’s picture

Issue summary: View changes
matthand’s picture

Status: Active » Postponed

On hold while seeking maintainer sign off on plan in parent issue.