function ModuleHandler::alter
Same name in other branches
- 9 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alter()
- 8.9.x core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alter()
- 10 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alter()
Overrides ModuleHandlerInterface::alter
2 calls to ModuleHandler::alter()
- ModuleHandler::alterDeprecated in core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php - Passes alterable variables to deprecated hook_TYPE_alter() implementations.
- ModuleHandler::reOrderModulesForAlter in core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php - Reorder modules for alters.
File
-
core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php, line 447
Class
- ModuleHandler
- Class that manages modules in a Drupal installation.
Namespace
Drupal\Core\ExtensionCode
public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
// Most of the time, $type is passed as a string, so for performance,
// normalize it to that. When passed as an array, usually the first item in
// the array is a generic type, and additional items in the array are more
// specific variants of it, as in the case of ['form', 'form_FORM_ID'].
if (is_array($type)) {
$cid = implode(',', $type);
}
else {
$cid = $type;
}
// Some alter hooks are invoked many times per page request, so store the
// list of functions to call, and on subsequent calls, iterate through them
// quickly.
if (!isset($this->alterEventListeners[$cid])) {
$hooks = is_array($type) ? array_map(static fn(string $type) => $type . '_alter', $type) : [
$type . '_alter',
];
$this->alterEventListeners[$cid] = $this->getCombinedListeners($hooks);
}
foreach ($this->alterEventListeners[$cid] as $listener) {
$listener($data, $context1, $context2);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.