Repository navigation
Drupal form and render callbacks - #565
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
In a Drupal project, a callback written as a string in a form or render array's callback keys (#submit, #validate, #process, #pre_render, the #ajax callback and the others Drupal calls) now leads to the method or function it names: go-to-definition, hover, find references and rename. '::method' names a method of the form it is written in, or of the trait; 'Class::method' and a class name joined to '::method' name a method of that class, the class name in the string read as fully qualified; a name without a colon names a global function. The playground's acme module has a form with a callback of each shape. Assisted-by: claude-code/claude-opus-5-5
In a Drupal project, a 'service:method' string in a form or render array's callback keys now leads to the method of the service's class: go-to-definition, hover, find references and rename, an alias leading to its target's class. The service part navigates to the service like any other service ID. The playground's greeting card has a lazy builder that names a method of the acme.greeter service. Assisted-by: claude-code/claude-opus-5-5
In a Drupal project, a string in a form or render array's callback keys now completes what it can name while it is typed: after '::', the public methods of the form it is written in, or of the trait; after 'Class::', the public methods of that class, the class name read as fully qualified; after 'service:', the public methods of the service's class; and before any colon, function names, written as their fully qualified names. A class name joined to '::' completes that class's methods. '::' completes nothing under the render callback keys, where Drupal does not call it on the form, and a value callback is offered only static methods and functions. The Drupal completion benchmark has a function and a method callback case. Assisted-by: claude-code/claude-opus-5-5
In a Drupal project, a callback in a form or render array's callback keys that cannot work is now reported. A callback naming an unknown method, function or class gets the usual unknown-member, unknown-function or unknown-class warning, array callables included, while array callables outside callback keys stay unchecked. A callback naming a private or protected method is reported as one Drupal cannot call from outside the class. '::method' in a render callback, which Drupal cannot resolve, and a value callback that is not a native callable, which Drupal ignores, get the new invalid_drupal_callback warning. '::method' outside a form, a method a trait lacks, and a name that is a class or a service stay silent. The playground's greeting form says how to see the warnings. Assisted-by: claude-code/claude-opus-5-5
Assisted-by: claude-code/claude-sonnet-5-5
The unknown-service check and the Drupal callback checks now ask the same DrupalServiceIds whether a site may declare a service, instead of each reading the declared IDs and the PHP-defined ones separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks |
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 DR11: a Drupal form or render callback written as a string navigates to the method or function it names, completes, and is checked.
#submit,#validate,#element_validate,#process,#after_build,#entity_builders,#pre_render,#post_render),#value_callback,#access_callback, the#ajaxcallbackand the first item of#lazy_builder, in Drupal projects only.'::method'names a method of the form when the code sits in a form class or a trait.'Class::method',X::class . '::method'and'service:method'name a method of that class or service, and a string without:names a global function. Class and function names in these strings are fully qualified, as Drupal reads them at run time.'::,'Class::and'service:, and function names elsewhere.invalid_drupal_callbackwarning reports a callback Drupal cannot call:'::method'in a render callback, an array callable that names a non-static method by its class, or a value callback that is not a native callable (Drupal ignores it).On Drupal core 11.4,
analyzereports 5 new warnings, all real: 3 in the*.api.phpexamples and 2 in abig_pipetest module that uses broken callbacks on purpose.Five follow-ups are filed in the roadmap:
'::method'in a form alter hook (DR32);How to test: run
composer installinexamples/drupal, openexamples/drupalwith this branch's build, then openweb/modules/custom/acme/src/Form/GreetingForm.phpand follow its "Try:" comments:validateNamein'::validateName', and ofacme_greeting_form_submit(it lands inacme.module).validateName(): the'::validateName'string follows.'::validateName', or make the method private, to see the warning.src/Controller/GreetingController.php, go to the definition ofbuildGreetingand ofacme.greeterin'acme.greeter:buildGreeting'.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.