I have a hook for pre_ and post_ user deletion event, like so (not exact code, just to explain the concept):
$this->eventManager->dispatch('user_delete_before');
$this->customerRepository->delete($magentoUser);
$this->eventManager->dispatch('user_delete_after', ['data' => $magentoUser]);
However, what I actually want is to allow the user_delete_before
hook to determine whether the user will be deleted. Something like this:
if ($this->eventManager->dispatch('user_delete_before')) {
$this->customerRepository->delete($magentoUser);
$this->eventManager->dispatch('user_delete_after', ['data' => $magentoUser]);
}
In order to allow the module implementer to easily inject their deletion logic.
Observers aren’t really designed to work this way (unless they are in Magento?), so what is the correct way to implement something like this?