Do you think it would be a good practice to replace hooks with events? I mean dispatching an event inside a hook to subscribe afterwards.
For example if you have 20 hooks in your module, is it recommended to dispatch an event for each hook, or just keep using the hooks as usual?
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function my_module_node_insert(EntityInterface $entity) {
// Dispatch the node insert event so that subscribers can act accordingly.
\Drupal::service('event_dispatcher')->dispatch(NodeInsertEvent::NODE_INSERT, new NodeInsertEvent($entity));
}
For example if you have 20 hooks in your .module file?
then you simply have 20 specific needs to subscribe to those hooks. You can't just route them all into a singular event, you'd probably wind up with multiple events subscribers which now turns 1 file into multiple (per module, potentially) and doesn't change the scenario very much. Like 4k4 said, this doesn't really benefit anyone until core maintainers implement such a thing in the future. The code you write here wouldn't be very portable without hauling the custom events everywhere you go.