Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll
13/04/2025, by Ivan

Hooks are one of the ways modules interact with other contributed modules or Drupal core subsystems. Hooks are used for a variety of tasks, including preprocessing variables for template files (hook_preprocess()), modifying information lists (hook_tokens_alter(), hook_views_data_alter()), and manipulating forms (hook_form_alter()), among other things. This page lists all hooks provided by core.

Modules can also define their own additional hooks. For example, the Flag module defines hook_flag_options_alter(), which can be used by other modules that want to alter the default options of an existing flag. Most modules that define hooks also provide documentation for them. This documentation is found in a *.api.php file.

Hooks are triggered at various points in Drupal's execution flow, where it looks for contributions from all enabled modules. For example, when a user visits the help page on a Drupal site, Drupal gives each module a chance to provide help documentation about itself. This is done by scanning all enabled modules for implementations of hook_help(). That is, functions named mymodule_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match), where “mymodule” is the name of the module. For example, the help hook in the Block module is called block_help(), and in the Node module it's node_help(). Hooks may have parameters; the parameters $route_name and $route_match allow developers to determine on which page(s) the help message should appear.

A hook can be thought of as an event listener in the sense that an event triggers an action. For example, an event in Drupal like node deletion will trigger the hook_node_delete. If your module implements hook_node_delete, that function will be called whenever a node is deleted. For instance, your function might decrement a node counter; when a node is deleted, your function is invoked and the count decreases by one.

See also the Module Hooks Overview in the Drupal API reference. You may also want to check out this excellent article that explains how Drupal’s module/hook system works using simple PHP constructs/snippets.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.