Problem/Motivation
theme.api.php still documents hook_extension(), a hook that Drupal 11.3.0 made obsolete. #1685492: Convert theme engines into services converted theme engines from .engine files into services tagged theme_engine, implementing ThemeEngineInterface. The ENGINE_extension() naming convention and the file-inclusion mechanism that would have called it no longer exist anywhere in core.
The function is not dead code in the sense of being unreachable at runtime — it was never really "called" as a conventional hook to begin with, it was a naming pattern the old .engine-file loader looked for. It is dead documentation: it tells anyone writing a new theme engine to implement a hook that nothing in current core invokes, instead of pointing them at ThemeEngineInterface and the theme_engine service tag that TwigThemeEngine actually uses.
Steps to reproduce
- Read
core/lib/Drupal/Core/Render/theme.api.phpon Drupal 11.3.0 or later (verified againstmainat commiteaba66f4, lines 810–822). - Find
hook_extension(), documented as "Declare a template file extension to be used with a theme engine," in theENGINE_extension()naming format:
function hook_extension(): string { // Extension for template base names in Twig. return '.html.twig'; } - Compare with how
TwigThemeEngineactually declares its extension today — a private class constant on the service, not a hook:
class TwigThemeEngine implements ThemeEngineInterface { protected const string EXTENSION = '.html.twig'; } - Search core and contrib for any caller of an
*_extension()function following this hook's naming convention: none exists.
Proposed resolution
Remove hook_extension() (theme.api.php, lines 810–822 at eaba66f4) and its docblock entirely. No deprecation period is needed: the hook is not invoked anywhere in core, and the mechanism that would have invoked it was already removed by #1685492: Convert theme engines into services. A follow-up documentation improvement (out of scope here) could add a short pointer from the theming/engine documentation to ThemeEngineInterface for anyone who lands on the old hook via search.
Remaining tasks
- Confirm (grep is sufficient) that no core or contrib code defines an
*_extension()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_extension(). No runtime behavior changes, since nothing in current core invokes this hook.
Data model changes
None.
Release notes snippet
Removed the obsolete hook_extension(), non-functional documentation left over from the pre-11.3 theme engine file system.
Comments
Comment #2
matthandComment #3
nicxvan commentedGood find!
I think we can clean up both of those in one issue here.
I don't think we need quite that much detail in the IS it amounts to update documentation.
I'm going to close the other issue.
Comment #4
nicxvan commentedComment #5
nicxvan commented