function hook_module_implements_alter

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

Alter the registry of modules implementing a hook.

This hook will be removed in 12.0.0. It is not deprecated in order to support the "#[LegacyModuleImplementsAlter]" attribute, used for compatibility with versions prior to Drupal 11.2.0.

Only procedural implementations are supported for this hook.

This hook is invoked in \Drupal::moduleHandler()->getImplementationInfo(). A module may implement this hook in order to reorder the implementing modules, which are otherwise ordered by the module's system weight.

Note that hooks invoked using \Drupal::moduleHandler->alter() can have multiple variations(such as hook_form_alter() and hook_form_FORM_ID_alter()). \Drupal::moduleHandler->alter() will call all such variants defined by a single module in turn. For the purposes of hook_module_implements_alter(), these variants are treated as a single hook. Thus, to ensure that your implementation of hook_form_FORM_ID_alter() is called at the right time, you will have to change the order of hook_form_alter() implementation in hook_module_implements_alter().

Parameters

array $implementations: An array keyed by the module's name. The value of each item corresponds to a $group, which is usually FALSE, unless the implementation is in a file named $module.$group.inc.

string $hook: The name of the module hook being implemented.

See also

\Drupal\Core\Hook\Attribute\LegacyModuleImplementsAlter

Related topics

6 functions implement hook_module_implements_alter()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

aaa_hook_order_test_module_implements_alter in core/modules/system/tests/modules/HookOrder/aaa_hook_order_test/aaa_hook_order_test.module
Implements hook_module_implements_alter().
module_handler_test_all1_module_implements_alter in core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all1/module_handler_test_all1.module
Implements hook_module_implements_alter().
module_implements_alter_test_legacy_module_implements_alter in core/tests/Drupal/Tests/Core/Extension/modules/module_implements_alter_test_legacy/module_implements_alter_test_legacy.module
Implements hook_module_implements_alter().
module_implements_alter_test_module_implements_alter in core/modules/system/tests/modules/module_implements_alter_test/module_implements_alter_test.module
Implements hook_module_implements_alter().
page_cache_form_test_module_implements_alter in core/modules/page_cache/tests/modules/page_cache_form_test.module
Implements hook_module_implements_alter().

... See full list

1 invocation of hook_module_implements_alter()
ModuleHandler::reOrderModulesForAlter in core/lib/Drupal/Core/Extension/ModuleHandler.php
Reorder modules for alters.

File

core/lib/Drupal/Core/Extension/module.api.php, line 126

Code

function hook_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter') {
    // Move my_module_form_alter() to the end of the list.
    // \Drupal::moduleHandler()->getImplementationInfo()
    // iterates through $implementations with a foreach loop which PHP iterates
    // in the order that the items were added, so to move an item to the end of
    // the array, we remove it and then add it.
    $group = $implementations['my_module'];
    unset($implementations['my_module']);
    $implementations['my_module'] = $group;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.