The functionality of hook_module_implements_alter is replaced with two new attributes and an order parameter on the #[Hook] attribute. Ordering must be done using new functionality.
Update existing hook_module_implements_alter code
This is not a typical deprecation and requires care for your module to support versions of Drupal older than 11.2
Follow these steps to update your module in a backwards compatible way;
- Achieve the same functionality as your
hook_module_implements_alter. Dynamic ordering is currently not supported. - Add the
#[LegacyModuleImplementsAlter]to your implementation ofhook_module_implements_alter. Once the minimum supported version of Drupal for the module is 11.2 or larger you may delete the entire function and attribute.
These change records provide examples for updating hook_module_implements_alter implementations.
- Order hook implementations with the order parameter.
- Reorder hook implementations in other modules with the #[ReOrderHook] attribute.
- Remove hook implementations the #[RemoveHook] attribute.
Examples of common patterns
Note: more complex patterns can occur in hook_module_implements_alter, but the three examples below cover most implementations.
Before: Ordering first
if ($hook === 'entity_bundle_info_alter') {
$group = $implementations['content_translation'];
$implementations = ['content_translation' => $group] + $implementations;
}
After:
#[Hook('entity_bundle_info_alter', order: Order::First)]
Before: Ordering last
if ($hook === 'entity_view_alter') {
$group = $implementations['layout_builder'];
unset($implementations['layout_builder']);
$implementations['layout_builder'] = $group;
}
After:
#[Hook('entity_view_alter', order: Order::Last)]
Before: Ordering before another implementation
if ($hook === 'system_breadcrumb_alter') {
$group = $implementations['layout_builder_test'];
$implementations = [
'layout_builder_test' => $group,
] + $implementations;
}
After:
#[Hook(
'system_breadcrumb_alter',
order: new OrderBefore(
modules: ['layout_builder']
)
)]