Topic

Hooks

Last updated January 5, 2018

Hooks allow modules to alter and extend the behavior of Drupal core, or another module. They are one of several ways that code components in Drupal can communicate with one another. Using hooks, a module developer can change how core or another module works--without changing the existing code. As a Drupal developer, understanding how to implement and invoke hooks is essential.

Example tasks

  • Get information, such as a list of links that should be placed in a user toolbar
  • Alter something, such as adding or removing a field from the content edit form
  • React to a system action, such as when a user cancels their account

Confidence

Hooks have been a staple of Drupal module development since the beginning. In Drupal 8, "info" hooks have generally been replaced by the plugin system and many "reactive" hooks have been replaced by events. Check api.drupal.org to see if a hook exists for Drupal 8.

Drupalize.Me resources

Below are some examples of the types of things you can do with hooks.

More Guides

We have guides on many Drupal skills and topics.

Explore guides

External resources

  • Hooks (api.drupal.org)
    • API reference page that describes how hooks operate in Drupal, with a list of hooks available for developers to implement.