Same name and namespace in other branches
  1. 6.x developer/hooks/core.php \hook_hook_info()
  2. 7.x modules/system/system.api.php \hook_hook_info()
  3. 8.9.x core/lib/Drupal/Core/Extension/module.api.php \hook_hook_info()
  4. 9 core/lib/Drupal/Core/Extension/module.api.php \hook_hook_info()

Defines one or more hooks that are exposed by a module.

Normally hooks do not need to be explicitly defined. However, by declaring a hook explicitly, a module may define a "group" for it. Modules that implement a hook may then place their implementation in either $module.module or in $module.$group.inc. If the hook is located in $module.$group.inc, then that file will be automatically loaded when needed. In general, hooks that are rarely invoked and/or are very large should be placed in a separate include file, while hooks that are very short or very frequently called should be left in the main module file so that they are always available.

See system_hook_info() for all hook groups defined by Drupal core.

Return value

array An associative array whose keys are hook names and whose values are an associative array containing:

  • group: A string defining the group to which the hook belongs. The module system will determine whether a file with the name $module.$group.inc exists, and automatically load it when required.

Related topics

3 functions implement hook_hook_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

module_handler_test_hook_info in core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.module
Implements hook_hook_info().
module_test_hook_info in core/modules/system/tests/modules/module_test/module_test.module
Implements hook_hook_info().
views_hook_info in core/modules/views/views.module
Implements hook_hook_info().

File

core/lib/Drupal/Core/Extension/module.api.php, line 84
Hooks related to module and update systems.

Code

function hook_hook_info() {
  $hooks['token_info'] = [
    'group' => 'tokens',
  ];
  $hooks['tokens'] = [
    'group' => 'tokens',
  ];
  return $hooks;
}