Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

The new #[RemoveHook] attribute can be used when you want to remove the implementation of a hook in another module. It accepts the following required parameters:

  • hook
  • class
  • method

You may place the #[RemoveHook] attribute on any class or method in the Hook namespace, however for organizational purposes it is recommended you put it on the method that requires you to remove the other implementation.

Example conversion for navigation_module_implementation_alter

Before

function navigation_module_implements_alter(&$implementations, $hook): void {
  if ($hook == 'help') {
    // We take over the layout_builder hook_help().
    unset($implementations['layout_builder']);
  }
}

After

use \Drupal\Core\Hook\Attribute\RemoveHook;
#[RemoveHook('help', class: LayoutBuilderHooks::class, method: 'help')]

For converting other functionality of hook_module_implements_alter see hook_module_implements_alter requires the #[LegacyHook] attribute and ordering must be done using new functionality.

Impacts: 
Module developers
Site templates, recipes and distribution developers