Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.
This repository was archived by the owner on Sep 26, 2024. It is now read-only.

M3 - Remove CommonSubscriber from examples #159

@dennisameling

Description

@dennisameling

In Mautic 3, the CommonSubscriber is removed, which was the recommended way to listen for events in Mautic 2.x. See UPGRADE-3.0.md for details.

The docs will need an update to reflect this change.

Previously, the code would have looked like:

<?php

namespace MauticPlugin\MyPluginBundle\EventListener;

use Mautic\LeadBundle\LeadEvents;
use Mautic\LeadBundle\Event\LeadEvent;
use Mautic\CoreBundle\EventListener\CommonSubscriber;

class LeadPostSaveSubscriber extends CommonSubscriber {
     /**
     * @return array
     */
    static public function getSubscribedEvents()
    {
        return array(
            LeadEvents::LEAD_POST_SAVE     => array('onLeadPostSave', 0),
        );
    }

    public function onLeadPostSave(LeadEvent $event)
    {
        $lead = $event->getLead();
        // Some logic here
    }
}

Now, the code should look like:

<?php

namespace MauticPlugin\MyPluginBundle\EventListener;

use Mautic\LeadBundle\LeadEvents;
use Mautic\LeadBundle\Event\LeadEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LeadPostSaveSubscriber implements EventSubscriberInterface {
    /**
     * @return array
     */
    static public function getSubscribedEvents()
    {
        return array(
            LeadEvents::LEAD_POST_SAVE     => array('onLeadPostSave', 0),
        );
    }

    public function onLeadPostSave(LeadEvent $event)
    {
        $lead = $event->getLead();
        // Some logic here        
    }
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions