Entity listener config

Hi,

I am working on a plugin and I would like to use a Doctrine Entity listener. (When the entity is updated I would like to do something). Making the entity listener is OK, but I don’t know what to put in config.php to make it work.

I tried this:

'mautic.mbi.doctrine.listener.newmatchlistener' => [
                'class'        => 'MauticPlugin\MbiBundle\EventListener\NewMatchListener',
                'tag'          => 'doctrine.orm.entity_listener',
                'tagArguments' => [
                    'event' => 'postUpdate',
                    'entity' =>  '\MauticPlugin\MbiBundle\Entity\NewMatch'
                ],
                'arguments' => [
                    'mautic.lead.model.lead',
                    'mautic.lead.model.list'
                ],
            ],

I appreciate your help, thanks in advance!

You have to dispatch event for this new entity first, only then it makes sense to subscribe to it.

Check how its done here: mautic/app/bundles/LeadBundle/Model/LeadModel.php at 4014cbab554d80f4769ca1e79c0314b393a02d35 · mautic/mautic · GitHub

Hi, thanks for your reply.

Normally I would have to dispatch my listener, but since it’s a Doctrine LifecycleEvent, it’s dispatched by Symfony. So in this case I have to only enable the listener. As far as I know…

So, I would like to enable my Doctrine listener via the config.php

I would try to somehow configure that with php code. config.php is mostly “deprecated” in favor of services.php and auto-wiring anyway.

1 Like