Repository navigation
Drupal event subscribers - #566
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
A subscriber's getSubscribedEvents() is read when it builds the map by assigning to the variable it returns ($events[KEY][] = ..., $events[KEY] = ..., $events = [...]), anywhere in the body, as well as when it returns a literal. Assisted-by: claude-code/claude-opus-5-5
A Drupal site reads each subscriber's getSubscribedEvents() as a Symfony project does, so the listener methods its map names go to their definition, hover, take part in references and rename, and are reported when the class has no such method. Event names become a kind both frameworks read. #[AsEventListener] stays Symfony-only, in the symbol map and in completion, since Drupal never honours it. Assisted-by: claude-code/claude-opus-5-5
A subscription keyed by a class constant (KernelEvents::REQUEST, self::X, static::X) declares the constant's value when it is a plain string literal, read with what the class inherits from its parents and interfaces. A subscriber keyed only by constants now counts as declaring event names, so dispatcher calls complete, navigate to and count its subscriptions. An X::class key and a constant built any other way declare nothing. Assisted-by: claude-code/claude-opus-5-5
In a Drupal site, the event name a dispatcher call takes completes with
every name the project's subscribers declare, goes to each subscription,
and shows how many listeners subscribe. This works on the contracts and
component interfaces and on \Drupal::service('event_dispatcher'). The
name a listener is added for in code completes too, but declares nothing.
Assisted-by: claude-code/claude-opus-5-5
A class constant a subscriber keys its map by is the event name it holds in another spelling. Go to definition on an event string offers the constant first, then every subscription, and Find References on the string, on the constant, or on the string the constant is initialized with lists the constant, its uses, and the dispatches as one event. A constant no subscriber keys by stays a plain constant, and renaming one never rewrites an event string. Assisted-by: claude-code/claude-opus-5-5
Assisted-by: claude-code/claude-opus-5-5
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 DR16: PHPantom now reads event subscribers in Drupal sites, as it already does in Symfony projects. Listener methods navigate and are checked, and event names complete and navigate in the event dispatcher's calls.
In Drupal sites
dispatch()and the dispatcher's other calls that take one:'acme.greeted'or onGREETEDlists the same places: the constant, its uses, the subscriptions and the dispatches. Renaming the constant never rewrites an event string.#[AsEventListener]stays Symfony-only, because Drupal's container ignores it.This also changes Symfony projects
Symfony and Drupal share the subscriber reader, so Symfony projects get these changes too:
$events[KernelEvents::REQUEST][] = …; return $events;. Most of Drupal core writes its maps this way.KernelEvents::REQUEST => …now declareskernel.request, an inherited constant included. That constant also becomes the event's definition for navigation and Find References. AFoo::classkey still declares nothing.Checked
analyzeon Drupal core 11.4 and on theredirectandflagmodules reports exactly whatmainreports.main.Roadmap
How to test
Run
composer installinexamples/drupal, openexamples/drupalwith this branch's build, and follow the "Try:" comments:web/modules/custom/acme/src/EventSubscriber/GreetingSubscriber.php: go to the definition of'onResponse', renameonResponse()(the string follows), and misspell'onConfigSave'to see the warning.web/modules/custom/acme/acme.module,acme_announce_greeting(): go to the definition of'acme.greeted', find its references, and clear it to complete an event name such askernel.request.web/modules/custom/acme/src/Event/GreetingEvents.php: find the references ofGREETED; the dispatch inacme.moduleis among them.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.