Skip to content

Document Mautic 8.0 class-name dispatch for AssetBundle events - #647

Draft
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/pr-17196-asset-events-by-class
Draft

Document Mautic 8.0 class-name dispatch for AssetBundle events#647
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/pr-17196-asset-events-by-class

Conversation

@promptless-for-oss

Copy link
Copy Markdown
Contributor

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\AssetEvents string constants. A Plugin whose subscriber is still keyed on an AssetEvents constant silently stops receiving the event — no exception and nothing logged — so it needs to re-key getSubscribedEvents() 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 as LeadEvents and PageEvents), 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 converted AssetEvents constant 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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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``.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirms getSubscribedEvents() in core AssetBundle listeners now keys on the event class (e.g. AssetPostSaveEvent::class) rather than the AssetEvents constant.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/EventListener/AssetSubscriber.php#L21-L27

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/Model/AssetModel.php#L347-L367

* 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/Model/AssetModel.php#L264-L267

* - ``mautic.asset_on_load``
- ``AssetEvents::ASSET_ON_LOAD``
- ``AssetLoadEvent``
* - ``mautic.asset_on_remote_browse``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/Controller/AjaxController.php#L48-L56

* - ``mautic.asset_on_remote_browse``
- ``AssetEvents::ASSET_ON_REMOTE_BROWSE``
- ``RemoteAssetBrowseEvent``
* - ``mautic.asset_pre_save``

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/Model/AssetModel.php#L347-L353

* 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Source: https://github.com/mautic/mautic/blob/2c143c2af1312cfa2a082bfadd380fd42e141f37/app/bundles/AssetBundle/AssetEvents.php#L18-L82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant