Problem/Motivation

theme.api.php still documents hook_render_template(), which is obsolete. Its documented body reaches directly into the Twig service:

function hook_render_template($template_file, $variables): string|\Stringable {
  $twig_service = \Drupal::service('twig');

  return $twig_service->loadTemplate($template_file)->render($variables);
}

This predates #1685492: Convert theme engines into services, which replaced the ENGINE_render_template() hook convention with theme engines as services implementing ThemeEngineInterface::renderTemplate(string $template_file, array $variables): string|MarkupInterface. TwigThemeEngine::renderTemplate() is the real, current implementation. hook_render_template() describes a mechanism core no longer uses and will mislead anyone using it as a reference for writing a new theme engine.

This is a companion cleanup to the issue removing hook_extension() — filed separately since they are two independent, single-function removals, but they should probably be linked once both are open.

Steps to reproduce

  1. Read core/lib/Drupal/Core/Render/theme.api.php on Drupal 11.3.0 or later (verified against main at commit eaba66f4, lines 824–849).
  2. Find hook_render_template(), documented as "Render a template using the theme engine."
  3. Compare with the actual current contract in core/lib/Drupal/Core/Theme/ThemeEngineInterface.php, which declares renderTemplate() as an interface method implemented by a service tagged theme_engine (see TwigThemeEngine::renderTemplate()), not a hook.

Proposed resolution

Remove hook_render_template() (theme.api.php, lines 824–849 at eaba66f4) and its docblock entirely, for the same reason as the companion hook_extension() removal. Point readers instead to ThemeEngineInterface for the current contract.

Remaining tasks

  • Confirm (grep is sufficient) that no core or contrib code defines an *_render_template() function relying on the old hook invocation.
  • Write the patch/MR removing the function and its docblock.
  • Review.

User interface changes

None.

Introduced terminology

None.

API changes

Removes the documented, but already non-functional, hook_render_template(). No runtime behavior changes, since nothing in current core invokes this hook.

Data model changes

None.

Release notes snippet

Removed the obsolete hook_render_template(), non-functional documentation left over from the pre-11.3 theme engine file system.

Comments

matthand created an issue. See original summary.

nicxvan’s picture

Status: Active » Closed (duplicate)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.