Key ChannelBundle event subscribers on the event class (Mautic 8.0) - #644
Key ChannelBundle event subscribers on the event class (Mautic 8.0)#644promptless-for-oss wants to merge 4 commits into
Conversation
Update the plugin Channels extension examples for the Mautic 8.0 class-name event dispatch introduced in mautic/mautic#17201: key subscribers on ChannelEvent::class and ChannelBroadcastEvent::class instead of the ChannelEvents string constants, drop the now-unused import, and correct the broadcast listener reference to the event class. Add a note explaining that subscribers keyed on the old ChannelEvents constants silently stop receiving these events.
| { | ||
| return [ | ||
| ChannelEvents::ADD_CHANNEL => ['onAddChannel', 100], | ||
| ChannelEvent::class => ['onAddChannel', 100], |
There was a problem hiding this comment.
ADD_CHANNEL subscriber example now keys on ChannelEvent::class. Confirmed: Mautic\ChannelBundle\Event\ChannelEvent is the event class, and mautic/mautic PR #17201's UPGRADE-8.0.md maps ChannelEvents::ADD_CHANNEL -> ChannelEvent.
| { | ||
| return [ | ||
| ChannelEvents::CHANNEL_BROADCAST => ['onChannelBroadcast', 0] | ||
| ChannelBroadcastEvent::class => ['onChannelBroadcast', 0], |
There was a problem hiding this comment.
Broadcast subscriber example now keys on ChannelBroadcastEvent::class. Confirmed: Mautic\ChannelBundle\Event\ChannelBroadcastEvent is the event class, and mautic/mautic PR #17201's UPGRADE-8.0.md maps ChannelEvents::CHANNEL_BROADCAST -> ChannelBroadcastEvent.
|
|
||
| .. note:: | ||
|
|
||
| From Mautic 8.0, Mautic dispatches and subscribes to these ChannelBundle events by their event class name (for example ``ChannelEvent::class``) rather than the ``ChannelEvents`` constant. A subscriber still keyed on the old ``ChannelEvents`` constant silently stops receiving the event, so re-key it on the event class. The ``ChannelEvents`` constants stay defined for backward compatibility but no longer route dispatch for these events. |
There was a problem hiding this comment.
Current note text (single sentence): from Mautic 8.0, subscribers to these ChannelBundle events key on the event class (e.g. ChannelEvent::class), following the Symfony convention of dispatching events by class name since Symfony 4.3. Verified against UPGRADE-8.0.md (added in mautic/mautic PR #17201), which documents the ChannelEvents constant -> event class rekeying for ADD_CHANNEL, CHANNEL_BROADCAST, MESSAGE_QUEUED, PROCESS_MESSAGE_QUEUE, PROCESS_MESSAGE_QUEUE_BATCH, and attributes the behavior to "Symfony 4.3+".
|
|
||
| .. note:: | ||
|
|
||
| From Mautic 8.0, Mautic dispatches and subscribes to these ChannelBundle events by their event class name (for example ``ChannelEvent::class``) rather than the ``ChannelEvents`` constant. A subscriber still keyed on the old ``ChannelEvents`` constant silently stops receiving the event, so re-key it on the event class. The ``ChannelEvents`` constants stay defined for backward compatibility but no longer route dispatch for these events. |
There was a problem hiding this comment.
Confirms Mautic\ChannelBundle\ChannelEvents constants class still exists, unmodified by PR #17201's diff, i.e. the constants are retained for backward compatibility even though they no longer route dispatch of the five converted events.
|
Thanks @adiati98 — will do. I'll swap the parentheses for a hyphen on |
|
Update: confirmed the spot — the aside |
Applies maintainer @adiati98's review on PR mautic#644: the dev-docs corpus sets off mid-sentence 'for example' asides with paired spaced hyphens (docs/design/labelling.rst), not parentheses.
|
Thanks @adiati98 — done. I've replaced the parentheses around the "for example" aside in the Mautic 8.0 note with the paired hyphen form the dev docs use elsewhere, so it now reads "...by their event class name - for example, |
|
|
||
| .. note:: | ||
|
|
||
| From Mautic 8.0, Mautic dispatches and subscribes to these ChannelBundle events by their event class name - for example, ``ChannelEvent::class`` - rather than the ``ChannelEvents`` constant. A subscriber still keyed on the old ``ChannelEvents`` constant silently stops receiving the event, so re-key it on the event class. The ``ChannelEvents`` constants stay defined for backward compatibility but no longer route dispatch for these events. |
There was a problem hiding this comment.
Perhaps we could find a way how to shorten these notes and also say that it's how Symfony does it since v4.3
|
Thanks @escopecz — good call. I'll tighten these notes and frame keying subscribers on the event class as the Symfony 4.3+ convention, and push an update here shortly. |
|
Update: verified against the 8.x source and revising the PR now. I'm shortening the note and framing this as the Symfony 4.3+ dispatch-by-event-class convention, and dropping the "silently stops receiving"/BC-framing. The corrected subscriber examples (keyed on |
Applies @escopecz's review on PR mautic#644: shorten the note added after the first subscriber example and state that keying subscribers on the event class is the Symfony convention since Symfony 4.3. Drops the silent-failure warning and backward-compatibility framing.
|
|
||
| .. note:: | ||
|
|
||
| From Mautic 8.0, key subscribers to these ChannelBundle events on the event class—for example, ``ChannelEvent::class``—following the Symfony convention for dispatching events by class name since Symfony 4.3. |
There was a problem hiding this comment.
Confirms the "since Symfony 4.3" attribution: Symfony 4.3 changed EventDispatcherInterface::dispatch() so the event name argument became optional (dispatch($event) instead of dispatch($eventName, $event)), and listeners/subscribers can key on the event's FQCN (e.g. OrderPlacedEvent::class) instead of an arbitrary string constant. This is the convention line 61 attributes to Symfony 4.3.
Source: https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching
|
@escopecz done — the note is now a single sentence attributing the pattern to the Symfony convention for dispatching events by class name (since Symfony 4.3). I also confirmed against the 8.x source that |
Open in Promptless
From Mautic 8.0, Mautic dispatches five ChannelBundle events by their event class name (the Symfony convention for dispatching events by class name since Symfony 4.3) instead of the
ChannelEvents::*string constants. This updates the plugin Channels extension page to reflect the new convention: the two subscriber examples now key onChannelEvent::classandChannelBroadcastEvent::class(priorities preserved), the now-unusedChannelEventsimport is dropped, and the broadcast listener reference is corrected to\Mautic\ChannelBundle\Event\ChannelBroadcastEvent. A concise note tells developers to key affected subscribers on the event class and attributes the pattern to Symfony 4.3. Reflects mautic/mautic#17201 (targets 8.x, documented on the 7.2 docs branch).Trigger Events
Review feedback addressed
docs/plugin_extensions/channels.rst): "Perhaps we could find a way how to shorten these notes and also say that it's how Symfony does it since v4.3" — Applied with the reviewer's intent. The Mautic 8.0 note is shortened to a single sentence directing developers to key subscribers to these ChannelBundle events on the event class (for example,ChannelEvent::class), following the Symfony convention for dispatching events by class name since Symfony 4.3. Verified against the 8.x source thatChannelEventsis kept (not removed), so the note drops the earlier "silently stops receiving" and "backward compatibility" framing rather than describing the constants as still-defined-but-unused. Vale passes on the changed line.docs/plugin_extensions/channels.rst): "we use hyphen instead of parentheses." — Applied. Thefor exampleaside in the note is set off without parentheses; the current single-sentence note uses em-dashes per the repo's ValeGoogle.EmDashrule.