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

M3 - Remove CommonSubscriber from examples #159

Open
dennisameling opened this issue Jul 9, 2020 · 0 comments
Open

M3 - Remove CommonSubscriber from examples #159

dennisameling opened this issue Jul 9, 2020 · 0 comments

Comments

@dennisameling
Copy link
Member

dennisameling commented Jul 9, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant