function ModuleHandler::reOrderModulesForAlter
Reorder modules for alters.
Parameters
list<string> $modules: A list of module names.
string $hook: The hook being worked on, for example form_alter.
Return value
list<string> The list, potentially reordered and changed by hook_module_implements_alter().
1 call to ModuleHandler::reOrderModulesForAlter()
- ModuleHandler::getCombinedListeners in core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php - Builds a list of implementations for an alter hook.
File
-
core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php, line 622
Class
- ModuleHandler
- Class that manages modules in a Drupal installation.
Namespace
Drupal\Core\ExtensionCode
protected function reOrderModulesForAlter(array $modules, string $hook) : array {
// Order by module order first, this preserves expected order for alter
// hooks implemented on behalf of other modules. The module that hooks
// implementations in kernel test classes are grouped by is 'core'. Since
// 'core' is not actually a module, add 'core' as a key to the module list,
// so core implementations are not filtered out. 'Core' is added last to
// match how kernel test hooks are added last by KernelTestCompilerPass.
// @todo Determine whether 'core' should still be ordered last by default
// when any service, including in the Drupal\Core namespace, can have
// hook implementations.
// @see https://www.drupal.org/i/3481903.
$modules = array_intersect(array_keys($this->moduleList + [
'core' => '',
]), $modules);
// Alter expects the module list to be in the keys.
$implementations = array_fill_keys($modules, FALSE);
// Let modules adjust the order solely based on the primary hook. This
// ensures the same module order regardless of whether this block
// runs. Calling $this->alter() recursively in this way does not
// result in an infinite loop, because this call is for a single
// $type, so we won't end up in this method again.
$this->alter('module_implements', $implementations, $hook);
return array_keys($implementations);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.