Drupal 8EventDispatcher vs HookYAML file for routingDependency Injection YAML file for routing Dependency Injection

Drupal 8 provide two way to alter original drupal core behaviours.

One way is using hook as Drupal 7, please check this blog for more detail.

Another way is using EventDispatcher. Here’s a tutorial on sitepoint to compare two of them.

For sure, Drupal 8 encourage useing the EventDispatcher to make all the logic decouple and testable. And Invoke hook may be totally removed on Drupal 9.

YAML file for routing

TBC

Dependency Injection

Using dependency injection, here’s the official documentation about the Dependency Injection.

And this is the mechanism behind the scene.