Repository navigation
Drupal render arrays, theme hooks, and libraries - #542
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
1 of 6 tasks
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
Contributor
|
Thanks, good timing too |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds DR7: the names a Drupal render array holds (
#theme,#type,#attachedlibraries) complete, go to their declaration and show details, and a theme hook's templates get the hook's variables.hook_theme()complete in#themeand#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.attributes,logged_in, …) complete, hover and navigate, typed from the render arrays that use the hook.#typenames complete and go to the element class, read from theRenderElementandFormElementattributes and annotations. An unknown name is reported.#attached, Twig'sattach_library(), a library'sdependenciesand a theme'slibraries. 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
#typesupport is ported from Luca Lusso's PHPlumb (MIT), with his agreement.How to test: run
composer installinexamples/drupal, then openexamples/drupalwith this branch's build. Inweb/modules/custom/acme/:src/Controller/GreetingController.php: go to the definition of'acme_greeting'to reachAcmeHooks::theme(), the module's template andacme_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: hovernameto seestring, passed by the controller. Complete afterattributes.to see theAttributemethods.acme.libraries.yml: go to the definition ofcore/drupalindependencies.Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json). Not applicable: this PR adds or changes no setting.the changes and why they are needed.
the changelog, and other user-facing content, and removed or corrected
anything inaccurate, unclear, or unnecessary.