Skip to content

Document Mautic 8 class-name dispatch for the DynamicContentBundle event - #645

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

Document Mautic 8 class-name dispatch for the DynamicContentBundle event#645
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/pr-17198-dynamiccontent-events-by-class

Conversation

@promptless-for-oss

Copy link
Copy Markdown
Contributor

Open in Promptless

Mautic 8 dispatches the DynamicContentBundle ContactFiltersEvaluateEvent by the event object alone (Symfony 4.3 class-name style), so the event class is now the event name and the DynamicContentEvents::ON_CONTACTS_FILTER_EVALUATE string constant is no longer used to dispatch it (though the constant remains in the codebase for backward compatibility). This adds a note to the "Available events" section of the plugin event-listeners page so plugin authors key a ContactFiltersEvaluateEvent subscriber on the event class instead of the old constant.

The note warns that a subscriber still keyed on the ON_CONTACTS_FILTER_EVALUATE constant (or its string value) silently stops firing under Mautic 8 — no exception, no log — and clarifies that the DynamicContentEvent CRUD group (PRE_SAVE/POST_SAVE/PRE_DELETE/POST_DELETE) still dispatches by its DynamicContentEvents constants because it shares one event object across four names. This mirrors the notes added for the sibling CoreBundle, IntegrationsBundle, PluginBundle, and CampaignBundle conversions.

Trigger Events


.. note::

Since Mautic 8, Mautic dispatches the ``ContactFiltersEvaluateEvent`` event by the event object alone, so the event class is the event name. 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.

Verifies: since Mautic 8, ContactFiltersEvaluateEvent is dispatched via $this->dispatcher->dispatch($event) with no name argument (Symfony 4.3+ style), so the event class is the event name. hasListeners(ContactFiltersEvaluateEvent::class) confirms the class itself is used as the lookup key. Note: doc text overgeneralizes this to "Mautic\DynamicContentBundle\Event events" (plural/whole namespace) rather than scoping to ContactFiltersEvaluateEvent specifically — see correction.

Source: https://github.com/mautic/mautic/blob/39b1297c4121d6a8820803b909c1124587a190ec/app/bundles/DynamicContentBundle/Helper/DynamicContentHelper.php#L241-L246


Since Mautic 8, Mautic dispatches the ``ContactFiltersEvaluateEvent`` event by the event object alone, so the event class is the event name. This matches the Symfony 4.3 dispatch style.

* Key ``getSubscribedEvents()`` on ``ContactFiltersEvaluateEvent::class``, not on the matching ``Mautic\DynamicContentBundle\DynamicContentEvents`` constant (``ON_CONTACTS_FILTER_EVALUATE``) or its string value.

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.

Verifies: core subscriber's getSubscribedEvents() keys on ContactFiltersEvaluateEvent::class, not on DynamicContentEvents::ON_CONTACTS_FILTER_EVALUATE or its string value 'mautic.dwc.on_contact_filters_evaluate'.

Source: https://github.com/mautic/mautic/blob/39b1297c4121d6a8820803b909c1124587a190ec/app/bundles/LeadBundle/EventListener/DynamicContentSubscriber.php#L21-L25

Since Mautic 8, Mautic dispatches the ``ContactFiltersEvaluateEvent`` event by the event object alone, so the event class is the event name. This matches the Symfony 4.3 dispatch style.

* Key ``getSubscribedEvents()`` on ``ContactFiltersEvaluateEvent::class``, not on the matching ``Mautic\DynamicContentBundle\DynamicContentEvents`` constant (``ON_CONTACTS_FILTER_EVALUATE``) or its string value.
* The ``DynamicContentEvents`` constants remain in the codebase but are no longer used to dispatch these events, so a subscriber still keyed on a converted constant won't fire. It fails silently: it throws no exception and logs nothing, and simply never runs.

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.

Verifies: ON_CONTACTS_FILTER_EVALUATE constant kept for backwards compatibility but no longer used internally to dispatch; a subscriber still keyed on the old constant simply won't receive the event (standard Symfony dispatcher behavior when no listener matches the dispatched name — no exception, no log). Constant retained at DynamicContentEvents.php L107 (https://github.com/mautic/mautic/blob/39b1297c4121d6a8820803b909c1124587a190ec/app/bundles/DynamicContentBundle/DynamicContentEvents.php#L100-L107).

Source: https://github.com/mautic/mautic/blob/39b1297c4121d6a8820803b909c1124587a190ec/UPGRADE-8.0.md#L283


* Key ``getSubscribedEvents()`` on ``ContactFiltersEvaluateEvent::class``, not on the matching ``Mautic\DynamicContentBundle\DynamicContentEvents`` constant (``ON_CONTACTS_FILTER_EVALUATE``) or its string value.
* The ``DynamicContentEvents`` constants remain in the codebase but are no longer used to dispatch these events, so a subscriber still keyed on a converted constant won't fire. It fails silently: it throws no exception and logs nothing, and simply never runs.
* Mautic 8 converted only events whose class maps to a single name. The ``DynamicContentEvent`` CRUD group (``PRE_SAVE``, ``POST_SAVE``, ``PRE_DELETE``, ``POST_DELETE``) shares one event object dispatched under four names, so keep keying on those ``DynamicContentEvents`` 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.

Verifies: DynamicContentModel::dispatchEvent() creates a single DynamicContentEvent object and dispatches it under one of four DynamicContentEvents constants (PRE_SAVE/POST_SAVE/PRE_DELETE/POST_DELETE) depending on $action, via $this->dispatcher->dispatch($event, $name) — confirms this CRUD family was not converted to the object-only dispatch style and still keys on the DynamicContentEvents constants.

Source: https://github.com/mautic/mautic/blob/39b1297c4121d6a8820803b909c1124587a190ec/app/bundles/DynamicContentBundle/Model/DynamicContentModel.php#L221-L256

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