Define and Invoke a New Hook for Drupal 8, Drupal 9, and Drupal 10

Last updated March 10, 2022
Module Development9.5.x/10.0.x

As a module developer you should define and invoke new hooks in your module in order to allow other developers -- or even future you -- to extend your module's functionality without hacking your module's code. This requires:

  • Creating a new, unique, name for your hook
  • Providing documentation for your hook
  • Invoking the hook at critical points in your code

By the end of this tutorial you should have a better idea of when to define a new hook and know how to invoke a hook from your code.