I am looking to remove a Doctrine Extensions life cycle event listener from within a controller.
I need to remove the listener for update events because I need to update all nodes in the tree at once. Something that is not supported by the library, but is possible by directly setting the correct left, right, level etc...
Is it possible to remove a life cycle even from within a controller? What is a possible solution for this situation.
I thought something like this might work, but it did not
$evm = $em->getEventManager();
$listener = new \Gedmo\Tree\TreeListener();
$evm->removeEventListener( array( 'postUpdate' ), $listener );
yes it will work, but there are different events used:
$listenerInst = null;
$em; /* entity manager */
foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
foreach ($listeners as $hash => $listener) {
if ($listener instanceof WantedListenerClass) {
$listenerInst = $listener;
break 2;
}
}
}
$listenerInst || die('Listener is not registered in the event manager');
// then you can remove events you like:
$evm = $em->getEventManager();
$evm->removeEventListener(array('onFlush'), $listenerInst);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With