Background
The order of hook implementations for a hook follows the order of the modules that provide these implementations.
This module order is based on module weights and alphabetical order of module machine names, and it can be altered with hook_module_implements_alter().
Since #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter, the order of individual implementations can be changed with newly introduced attributes, or with a new parameter in the #[Hook] attribute. (see other change records).
Before
When one module provides multiple implementations for the same hook, their order relative to each other is not guaranteed. It depends on the order of discovery, which can be system-dependent.
Especially, when one module provides one procedural hook implementation and one or more OOP hook implementations for the same hook, it is not guaranteed whether the procedural implementation will run first, last, or in between the OOP implementations.
After
When invoking a hook, any procedural hook implementation will be executed before any OOP hook implementations of the same module, unless overridden by order settings in attributes.
Example
Prior to this change, hook implementations of hook_myhook() might be ordered like this:
- module_a_myhook()
- Drupal\module_a\Hook\Hooks::myHook()
- Drupal\module_b\Hook\Hooks::myHook()
- module_b_myhook()
After this change, they would be ordered like this:
- module_a_myhook()
- Drupal\module_a\Hook\Hooks::myHook()
- module_b_myhook()
- Drupal\module_b\Hook\Hooks::myHook()