diff --git a/Resources/doc/entity-listeners.rst b/Resources/doc/entity-listeners.rst index 120787b29..92251676e 100644 --- a/Resources/doc/entity-listeners.rst +++ b/Resources/doc/entity-listeners.rst @@ -1,10 +1,61 @@ Entity Listeners ================ -Entity listeners that are services must be registered with the entity -listener resolver. You can tag your entity listeners and they will automatically -be added to the resolver. Use the entity_manager attribute to specify which -entity manager it should be registered with. Example: +Entity listeners that are services must be registered with the entity listener +resolver. On top of the annotation 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. + +Full example: + +.. code-block:: php + + + + + + + + + + + + + +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: .. configuration-block:: @@ -14,14 +65,11 @@ entity manager it should be registered with. Example: user_listener: class: \UserListener tags: - - - name: doctrine.orm.entity_listener - event: postPersist - entity: App\Entity\User - name: doctrine.orm.entity_listener event: preUpdate entity: App\Entity\User + # Entity manager name is optional entity_manager: custom .. code-block:: xml @@ -33,13 +81,9 @@ entity manager it should be registered with. Example: + - -If you use a version of doctrine/orm < 2.5 you have to register the entity listener in your entity as well: - -.. code-block:: php - - -