developer-documentation icon indicating copy to clipboard operation
developer-documentation copied to clipboard

M3 - Remove CommonSubscriber from examples

Open dennisameling opened this issue 5 years ago • 0 comments

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.

dennisameling avatar Jul 09 '20 14:07 dennisameling