In my application, I created a listener for onPostSubmit event in forms.
I created a new class that implement EventSubscriberInterface.
In the builderForm I added the evnet subscriber like this :
->addEventSubscriber(new MyNewListener())
Everything is working well, but not as I would like...
In my listener, I need the entity manager to query the database.
The first solution I have found is to add the entity manager in the form via the options and pass it to the listener via the constructor. The code is now :
->addEventSubscriber(new MyNewListener($options['entity_manager']))
This solution works but I don't want to use it like this, I prefer to use a service and add the entity manager in the service definition.
Then, my question is: How to declare the listener as a service (and pass the entity manager) and how to call it in the form declaration ?
Thank you for your help.