Skip to content

Drupal render arrays, theme hooks, and libraries - #542

Merged
AJenbo merged 6 commits into
PHPantom-dev:mainfrom
giuseppe-esposito-87:drupal-dr7
Nov 6, 2026
Merged

AJenbo merged 6 commits into
PHPantom-dev:mainfrom
giuseppe-esposito-87:drupal-dr7

Conversation

@giuseppe-esposito-87

Copy link
Copy Markdown
Contributor

🤖 This was written by an AI agent on behalf of @giuseppe-esposito-87 (claude-code/claude-opus-5-5).

Adds DR7: the names a Drupal render array holds (#theme, #type, #attached libraries) complete, go to their declaration and show details, and a theme hook's templates get the hook's variables.

  • Theme hooks. Names from every hook_theme() complete in #theme and #theme_wrappers, go to the declaring entry, the template and each theme's override, and show the hook's variables on hover. A suggestion (node__article) leads to its base hook. The hook's # variables complete in the render array.
  • Template variables. In a theme hook's Twig templates, the hook's variables and the ones Drupal adds to every template (attributes, logged_in, …) complete, hover and navigate, typed from the render arrays that use the hook.
  • Render elements. #type names complete and go to the element class, read from the RenderElement and FormElement attributes and annotations. An unknown name is reported.
  • Libraries. Library names complete, go to their entry in the libraries file and show its version, in #attached, Twig's attach_library(), a library's dependencies and a theme's libraries. An unknown name is reported, unless its extension adds libraries in code.

A warning for unknown theme hook names is filed as DR24: Views builds hooks in loops, and a hook name does not say which extension declares it.

The #type support is ported from Luca Lusso's PHPlumb (MIT), with his agreement.

How to test: run composer install in examples/drupal, then open examples/drupal with this branch's build. In web/modules/custom/acme/:

  • src/Controller/GreetingController.php: go to the definition of 'acme_greeting' to reach AcmeHooks::theme(), the module's template and acme_theme's override. Go to the definition of 'acme_greeting_card' to reach its element class, and hover 'acme/greeting' to see its libraries file.
  • templates/acme-greeting.html.twig: hover name to see string, passed by the controller. Complete after attributes. to see the Attribute methods.
  • acme.libraries.yml: go to the definition of core/drupal in dependencies.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, examples/)
  • I have updated the config schema (config-schema.json). Not applicable: this PR adds or changes no setting.
  • I have added/updated tests to cover my changes
  • If I used AI tools, I have reviewed what they produced and can explain
    the changes and why they are needed.
  • I have read through any AI-generated text, especially documentation,
    the changelog, and other user-facing content, and removed or corrected
    anything inaccurate, unclear, or unnecessary.

@codecov-commenter

Copy link
Copy Markdown

A `#type` in a render array completes from the elements the site's
`#[RenderElement]` and `#[FormElement]` classes declare, or the
annotations older code uses, core's included. It goes to the element's
class, hovers it, and a name no element declares is reported.

Assisted-by: claude-code/claude-opus-5-5
Theme hook names in a render array's `#theme` and `#theme_wrappers`
complete from the hooks the site's `hook_theme()` implementations
declare, core's common elements included, and navigate to the hook's
entry and to its templates: the default one and every theme's override,
or for a suggestion the theme's template for it. Hover shows the
declaring extension, the template, and the variables. The `#` keys of a
render array whose `#theme` names a hook complete and navigate as the
hook's variables. Templates are found in folders the site's `.gitignore`
hides.

Assisted-by: claude-code/claude-opus-5-5
Library names complete, go to their key in the libraries file, and hover
with that file and the library's version, wherever Drupal reads one: the
`library` list of a render array's `#attached`, a template's
`attach_library()`, the `dependencies` of a library, and the `libraries`
of a theme's info file. Libraries files join the Drupal declaration-file
scan, so core's are read and a test module's count only while it is open.

Assisted-by: claude-code/claude-opus-5-5
A library name that no libraries file declares is reported wherever Drupal
reads one: a render array's `#attached`, a template's `attach_library()`, a
library's `dependencies`, and a theme's `libraries`. A name under a module
that implements `hook_library_info_build()` or `hook_library_info_alter()`
may be added in code and is not reported, and neither are test modules'
names in test code.

Assisted-by: claude-code/claude-opus-5-5
A theme hook's templates (the default one, a theme's override, and a
theme's template for a suggestion) receive the hook's declared variables,
or its render element, and the variables Drupal adds to every template.
They complete, hover, and navigate to their key in `hook_theme()`, and
are typed by the `#` keys of the render arrays whose `#theme` names the
hook. The attributes variables hold core's template `Attribute`. A
template no theme hook claims is unchanged.

Assisted-by: claude-code/claude-opus-5-5
…aries

Assisted-by: claude-code/claude-opus-5-5
@AJenbo
AJenbo merged commit 385b41e into PHPantom-dev:main Nov 6, 2026
13 of 15 checks passed
@AJenbo

AJenbo commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thanks, good timing too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants