I use symfony and easy admin and I want to listen event easy_admin.pre_persist.
In easy admin controller it calls this event like this:
$this->dispatch(EasyAdminEvents::PRE_PERSIST, array('entity' => $entity));
and this consts:
/** @Event("Symfony\Component\EventDispatcher\GenericEvent") */
const PRE_PERSIST = 'easy_admin.pre_persist';
If I in the same controller add listener for this event like this:
$ed = $this->get('event_dispatcher');
$ed->addListener('easy_admin.pre_persist', function($e) {
echo 'it works!';
die();
});
...it works.
But I want to add this listener in something other place. I think services.yml will be good place for it. I've read in Sf documentation i should add service this way:
# app/config/services.yml
services:
app.exception_listener:
class: AppBundle\EventListener\ExceptionListener
tags:
- { name: kernel.event_listener, event: kernel.exception }
but there is 2 properies - name and event. I know only event name, easy_admin.pre_persist.
How it works? What is name for this event and what is event?
If I can add listener for easy_admin.pre_persist how can I add this listener to services.yml?