Hooks, plugins, and events

Now that we have seen what the core libraries, modules, and themes do, let's talk briefly about hooks and events to understand how they are all connected.

Hooks are a very typical Drupal procedural concept that allows Drupal core and modules to basically ask for data from other modules and themes (or expose it). By doing this, the latter can provide a new functionality or alter the existing ones. It is the responsibility of the code that calls the hook to make use of whatever the hook implementations return. The format and interface for what the latter need to return is usually documented in the hook documentation.

Concretely, hooks work by scanning installed modules and themes and looking for a function that follows ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.