Entity listeners that are services must be registered with the entity listener
resolver. On top of the annotation/attribute in the entity class, you have to tag the
service with doctrine.orm.entity_listener for it to be automatically added
to the resolver. Use the (optional) entity_manager attribute to specify
which entity manager it should be registered with.
services:App\UserListener:tags:# Minimal configuration below-{name:doctrine.orm.entity_listener}# Or, optionally, you can give the entity manager name as below#- { name: doctrine.orm.entity_listener, entity_manager: custom }
Starting with doctrine/orm 2.5 and Doctrine bundle 1.5.2, instead of registering
the entity listener on the entity, you can declare all options from the service
definition:
services:App\UserListener:tags:-name:doctrine.orm.entity_listenerevent:preUpdateentity:App\Entity\User# entity_manager attribute is optionalentity_manager:custom# method attribute is optionalmethod:validateEmail
The event attribute is required if the entity listener is not registered on
the entity. If you don't specify the method attribute, it falls back on the
subscribed event name.
Starting with Doctrine bundle 1.12, if this method does not exist but if your entity listener is invokable, it falls
back on the __invoke() method.