Document Mautic 8.0 class-name dispatch for AssetBundle events - #647
Document Mautic 8.0 class-name dispatch for AssetBundle events#647promptless-for-oss wants to merge 1 commit into
Conversation
Since Mautic 8, AssetBundle events dispatch by event class (Symfony 4.3 style) instead of the Mautic\AssetBundle\AssetEvents string constants. Add a migration reference and note to the Available events section so plugin developers re-key subscribers on the event class; a subscriber left keyed on the old constant fails silently. Documents mautic/mautic#17196.
|
|
||
| .. note:: | ||
|
|
||
| Since Mautic 8, Mautic dispatches events in the ``Mautic\AssetBundle\AssetEvents`` family by the event class itself rather than by a string name—the class you dispatch is the name Symfony matches against. This matches the Symfony 4.3 dispatch style. |
There was a problem hiding this comment.
Confirms AssetBundle events are now dispatched by the event object alone (Symfony 4.3+ style) instead of the AssetEvents string constants, per PR #17196 / UPGRADE-8.0.md.
Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/UPGRADE-8.0.md#L268
|
|
||
| Since Mautic 8, Mautic dispatches events in the ``Mautic\AssetBundle\AssetEvents`` family by the event class itself rather than by a string name—the class you dispatch is the name Symfony matches against. This matches the Symfony 4.3 dispatch style. | ||
|
|
||
| * Key ``getSubscribedEvents()`` on the event class, for example ``AssetLoadEvent::class`` (in the ``Mautic\AssetBundle\Event`` namespace), not on the ``AssetEvents::*`` constant or the raw string name such as ``mautic.asset_on_load``. |
There was a problem hiding this comment.
Confirms getSubscribedEvents() in core AssetBundle listeners now keys on the event class (e.g. AssetPostSaveEvent::class) rather than the AssetEvents constant.
| Since Mautic 8, Mautic dispatches events in the ``Mautic\AssetBundle\AssetEvents`` family by the event class itself rather than by a string name—the class you dispatch is the name Symfony matches against. This matches the Symfony 4.3 dispatch style. | ||
|
|
||
| * Key ``getSubscribedEvents()`` on the event class, for example ``AssetLoadEvent::class`` (in the ``Mautic\AssetBundle\Event`` namespace), not on the ``AssetEvents::*`` constant or the raw string name such as ``mautic.asset_on_load``. | ||
| * The ``AssetEvents`` constants remain in the codebase but are no longer used for dispatch, so a subscriber still keyed on the constant or string won't fire. It fails silently—no exception, no log entry, and the listener never runs. To confirm your re-keyed listener now fires on the event class, run ``bin/console debug:event-dispatcher``, which lists the registered listeners per event and accepts an event class to filter by. |
There was a problem hiding this comment.
Confirms dispatch now resolves the event class via a match() on action and calls single-arg $this->dispatcher->dispatch($event); the AssetEvents string constants (still defined in AssetEvents.php) are no longer passed to dispatch(), so a listener keyed on the old string/constant is simply never invoked (Symfony EventDispatcher name-based routing), with no exception or log.
| * Key ``getSubscribedEvents()`` on the event class, for example ``AssetLoadEvent::class`` (in the ``Mautic\AssetBundle\Event`` namespace), not on the ``AssetEvents::*`` constant or the raw string name such as ``mautic.asset_on_load``. | ||
| * The ``AssetEvents`` constants remain in the codebase but are no longer used for dispatch, so a subscriber still keyed on the constant or string won't fire. It fails silently—no exception, no log entry, and the listener never runs. To confirm your re-keyed listener now fires on the event class, run ``bin/console debug:event-dispatcher``, which lists the registered listeners per event and accepts an event class to filter by. | ||
| * Other event families, such as ``LeadEvents`` and ``PageEvents``, still use their constants. Keep keying on those. | ||
| * Mautic removed the dead ``ASSET_ON_UPLOAD`` constant, which it never dispatched or listened to. |
There was a problem hiding this comment.
Confirms "The dead ASSET_ON_UPLOAD constant (never dispatched or listened to) has been removed." Verified absent from AssetEvents.php at head SHA and present in the 8.x base with no dispatch/subscriber usage anywhere in the codebase.
Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/UPGRADE-8.0.md#L268
| * - Old event name | ||
| - AssetEvents constant | ||
| - New event class | ||
| * - ``mautic.asset_on_load`` |
There was a problem hiding this comment.
Confirms mautic.asset_on_load / AssetEvents::ASSET_ON_LOAD is dispatched via new AssetLoadEvent($download, $isUnique); single-arg dispatch($event), matching the table row mapping ASSET_ON_LOAD -> AssetLoadEvent.
| * - ``mautic.asset_on_load`` | ||
| - ``AssetEvents::ASSET_ON_LOAD`` | ||
| - ``AssetLoadEvent`` | ||
| * - ``mautic.asset_on_remote_browse`` |
There was a problem hiding this comment.
Confirms mautic.asset_on_remote_browse / AssetEvents::ASSET_ON_REMOTE_BROWSE is dispatched via new RemoteAssetBrowseEvent($integration); single-arg dispatch($event), matching the table row mapping ASSET_ON_REMOTE_BROWSE -> RemoteAssetBrowseEvent.
| * - ``mautic.asset_on_remote_browse`` | ||
| - ``AssetEvents::ASSET_ON_REMOTE_BROWSE`` | ||
| - ``RemoteAssetBrowseEvent`` | ||
| * - ``mautic.asset_pre_save`` |
There was a problem hiding this comment.
Confirms the CRUD group mapping: pre_save/post_save/pre_delete/post_delete resolve via match() to AssetPreSaveEvent::class, AssetPostSaveEvent::class, AssetPreDeleteEvent::class, AssetPostDeleteEvent::class, matching table rows for ASSET_PRE_SAVE, ASSET_POST_SAVE, ASSET_PRE_DELETE, ASSET_POST_DELETE.
| * Other event families, such as ``LeadEvents`` and ``PageEvents``, still use their constants. Keep keying on those. | ||
| * Mautic removed the dead ``ASSET_ON_UPLOAD`` constant, which it never dispatched or listened to. | ||
|
|
||
| The following table is the complete migration reference for AssetBundle event subscribers. It maps each old event name and ``AssetEvents`` constant to its new event class. All new event classes live in the ``Mautic\AssetBundle\Event`` namespace, and ``app/bundles/AssetBundle/AssetEvents.php`` defines the constants. |
There was a problem hiding this comment.
Confirms all six AssetEvents string constants (ASSET_ON_LOAD, ASSET_ON_REMOTE_BROWSE, ASSET_PRE_SAVE, ASSET_POST_SAVE, ASSET_PRE_DELETE, ASSET_POST_DELETE) remain defined in AssetEvents.php with their exact string values for backward compatibility, and that ON_CAMPAIGN_TRIGGER_DECISION / ON_DETERMINE_DOWNLOAD_RATE_WINNER remain unconverted string constants.
Open in Promptless
Since Mautic 8, the AssetBundle dispatches its events by the event class (Symfony 4.3 dispatch style) instead of the
Mautic\AssetBundle\AssetEventsstring constants. A Plugin whose subscriber is still keyed on anAssetEventsconstant silently stops receiving the event — no exception and nothing logged — so it needs to re-keygetSubscribedEvents()on the event class.This updates the "Available events" section of
docs/plugins/event_listeners.rst: it scopes the existing "always use the event constants" guidance to the families that still dispatch by string constant (such asLeadEventsandPageEvents), adds a note explaining the class-based dispatch, the silent-failure consequence, and how to confirm a re-keyed listener, and adds a migration-reference table mapping each convertedAssetEventsconstant and its old event name to its new event class. It follows the same documentation pattern as the merged CoreBundle, CampaignBundle, and PluginBundle conversions.Documents mautic/mautic#17196.
Trigger Events