Search code examples
symfonydoctrine-ormlistener

How to control Doctrine Event subscriber priorities


I have an entity which I have two separate event subscribers listen to postPersist and postUpdate events to trigger particular actions. In the EventDispatcher component in Symfony the listeners could have priority attached to them but I do not seem to find the priority option for Doctrine events. Is there a way to have the subscribers prioritized or Doctrine event dispatcher doesn't support it, I really can't seem to find the right option for that.


Solution

  • Define your event listeners as a service and then you can set priority.

    E.g. from this answer.

    Can I define the order in which event listeners / subscribers are called in doctrine?