Skip to content

Document Mautic 8 class-name dispatch for Form, Integration, and Focus events - #658

Open
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/pr-17223-form-integration-focus-events-by-class
Open

Document Mautic 8 class-name dispatch for Form, Integration, and Focus events#658
promptless-for-oss wants to merge 1 commit into
mautic:7.2from
Promptless:promptless/pr-17223-form-integration-focus-events-by-class

Conversation

@promptless-for-oss

Copy link
Copy Markdown
Contributor

Open in Promptless

Mautic 8 dispatches seven events across FormBundle, IntegrationsBundle, and MauticFocusBundle by their event object (the Symfony 4.3+ convention) instead of the old *Events string constants. A plugin whose subscriber or kernel.event_listener-tagged service still keys on a converted constant silently stops receiving the event — no exception and no log entry — so developers upgrading to Mautic 8 need to know which events changed and re-key their listeners on the event class.

This adds a subsection to the "Available events" page of the plugin developer docs covering the seven converted events (constant → new event class), the namespace difference for the plugins/-based MauticFocusBundle, the events intentionally left as string constants, the mautic.form_on_submit Webhook type-identifier exception, the distinct FocusEventTypes::FOCUS_ON_VIEW stat-type identifier, a before/after getSubscribedEvents() example, and a bin/console debug:event-dispatcher verification tip. Follows the same template as the sibling bundle-migration documentation in this series.

Trigger Events

- New event class
* - FormBundle
- ``mautic.form_on_submit``
- ``FormEvents::FORM_ON_SUBMIT``

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 FormEvents constant string values: FORM_ON_SUBMIT='mautic.form_on_submit' (L88), FORM_ON_BUILD='mautic.form_on_build' (L74), ON_OBJECT_COLLECT='mautic.form.on_object_collect' (L128), ON_FIELD_COLLECT='mautic.form.on_field_collect' (L136).

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/FormBundle/FormEvents.php#L74-L136

- ``Mautic\FormBundle\Event\FieldCollectEvent``
* - IntegrationsBundle
- ``mautic.integration.INTEGRATION_FIND_INTERNAL_RECORDS``
- ``IntegrationEvents::INTEGRATION_FIND_INTERNAL_RECORDS``

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 IntegrationEvents constant string values: INTEGRATION_FIND_INTERNAL_RECORDS='mautic.integration.INTEGRATION_FIND_INTERNAL_RECORDS' (L91), INTEGRATION_FIND_OWNER_IDS='mautic.integration.INTEGRATION_FIND_OWNER_IDS' (L98).

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/IntegrationsBundle/IntegrationEvents.php#L91-L98

- ``Mautic\IntegrationsBundle\Event\InternalObjectOwnerEvent``
* - MauticFocusBundle
- ``mautic.focus.on_view``
- ``FocusEvents::FOCUS_ON_VIEW``

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.

- ``FocusEvents::FOCUS_ON_VIEW``
- ``MauticPlugin\MauticFocusBundle\Event\FocusViewEvent``

The FormBundle event classes live in the ``Mautic\FormBundle\Event`` namespace and the IntegrationsBundle event classes in the ``Mautic\IntegrationsBundle\Event`` namespace, both under ``app/bundles/``. MauticFocusBundle is a Plugin under ``plugins/``, so its event class is in the ``MauticPlugin\MauticFocusBundle\Event`` namespace. Note the different top-level namespace.

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\FormBundle\Event namespace under app/bundles/ for the converted FormBundle event classes (SubmissionEvent, FormBuilderEvent, ObjectCollectEvent, FieldCollectEvent all live in app/bundles/FormBundle/Event/).

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/FormBundle/Event/SubmissionEvent.php#L1-L8

- ``FocusEvents::FOCUS_ON_VIEW``
- ``MauticPlugin\MauticFocusBundle\Event\FocusViewEvent``

The FormBundle event classes live in the ``Mautic\FormBundle\Event`` namespace and the IntegrationsBundle event classes in the ``Mautic\IntegrationsBundle\Event`` namespace, both under ``app/bundles/``. MauticFocusBundle is a Plugin under ``plugins/``, so its event class is in the ``MauticPlugin\MauticFocusBundle\Event`` namespace. Note the different top-level namespace.

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 MauticPlugin\MauticFocusBundle\Event namespace under plugins/ for FocusViewEvent.

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/plugins/MauticFocusBundle/Event/FocusViewEvent.php#L1-L8


.. warning::

The string value of ``FormEvents::FORM_ON_SUBMIT`` is ``mautic.form_on_submit``, which is also the persisted Webhook event-type identifier in ``WebhookSubscriber``. Only the event-dispatch subscription moved to ``SubmissionEvent::class``. Webhook configuration and the type identifier are unaffected, so only your event-subscription code needs to change.

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 WebhookSubscriber::getSubscribedEvents() rekeyed to SubmissionEvent::class (L24) while FormEvents::FORM_ON_SUBMIT string constant is still used as the webhook type identifier in onWebhookBuild()/onFormSubmit() (L40, L46).

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/FormBundle/EventListener/WebhookSubscriber.php#L20-L47


.. warning::

``FocusEventTypes::FOCUS_ON_VIEW`` is a separate stat-type identifier and is untouched. Only ``FocusEvents::FOCUS_ON_VIEW`` converted to class-name dispatch. Don't confuse the two.

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 FocusEventTypes::FOCUS_ON_VIEW = 'focus.on_view' is a distinct class/value from FocusEvents::FOCUS_ON_VIEW ('mautic.focus.on_view'), left untouched by the PR.

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/plugins/MauticFocusBundle/FocusEventTypes.php#L12


The FormBundle event classes live in the ``Mautic\FormBundle\Event`` namespace and the IntegrationsBundle event classes in the ``Mautic\IntegrationsBundle\Event`` namespace, both under ``app/bundles/``. MauticFocusBundle is a Plugin under ``plugins/``, so its event class is in the ``MauticPlugin\MauticFocusBundle\Event`` namespace. Note the different top-level namespace.

Only these seven events changed. Mautic keeps an event as a string constant when several event names share one event object, or when the event crosses bundle boundaries, so those events still dispatch by the string name. For example, the IntegrationsBundle ``INTEGRATION_CONFIG_*`` before-and-after pair reuses one ``ConfigSaveEvent``, and FormBundle's create, read, update, and delete group constants do the same. For those, the guidance in the "Available events" intro to always use the event constants still holds.

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 IntegrationEvents::INTEGRATION_CONFIG_BEFORE_SAVE/AFTER_SAVE remain string-constant dispatch, reusing one ConfigSaveEvent object ($configEvent) across both dispatch calls; not converted to class-name dispatch by this PR.

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/IntegrationsBundle/Controller/ConfigController.php#L129-L144

public static function getSubscribedEvents(): array
{
return [
FormEvents::FORM_ON_SUBMIT => ['onFormSubmit', 0],

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 a real subscriber rekeyed from FormEvents::FORM_ON_SUBMIT to SubmissionEvent::class in getSubscribedEvents(), matching the before/after code example pattern shown in the docs.

Source: https://github.com/mautic/mautic/blob/1d1dd2bc7f591d5c174fe7ab75830b58a25f6d6b/app/bundles/LeadBundle/EventListener/SetContactAvatarFormSubscriber.php#L22-L25

public static function getSubscribedEvents(): array
{
return [
SubmissionEvent::class => ['onFormSubmit', 0],

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.

Source PR "[events] dispatch Form, Integrations and Focus bundle events by class name" (base 8.x); its UPGRADE-8.0.md addition documents the same seven-event mapping, the WebhookSubscriber/webhook-type-id exception, and the FocusEventTypes exception described in this doc subsection.

Source: mautic/mautic#17223

@TomasVotruba TomasVotruba left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants