What is a Drupal hook?

A hook is a way for modules to interact with Drupal core and other modules. You implement a hook by defining a function with a specific name pattern in your module file.

For example, hook_form_alter lets you modify any form before it is rendered. To implement it, define a function called modulename_form_alter in your module file.

Drupal calls every implementation of that hook at the right moment, letting modules cooperate without tight coupling. There are hundreds of hooks covering everything from node saving to user login to cron runs. The official documentation has a complete list with examples. Modern Drupal is moving away from some hooks towards event subscribers and plugins, but hooks remain fundamental to how modules extend the platform. Understanding them is essential for any Drupal developer.

Facebook
Twitter
LinkedIn
Pinterest