function ModuleHandler::alterDeprecated

Same name in other branches
  1. 9 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alterDeprecated()
  2. 8.9.x core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alterDeprecated()
  3. 10 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alterDeprecated()

Overrides ModuleHandlerInterface::alterDeprecated

File

core/lib/Drupal/Core/Extension/ModuleHandler.php, line 492

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

public function alterDeprecated($description, $type, &$data, &$context1 = NULL, &$context2 = NULL) {
    // Invoke the alter hook. This has the side effect of populating
    // $this->alterEventListeners.
    $this->alter($type, $data, $context1, $context2);
    // The $type parameter can be an array. alter() will deal with this
    // internally, but we have to extract the proper $cid in order to discover
    // implementations.
    $cid = $type;
    if (is_array($type)) {
        $cid = implode(',', $type);
        $extra_types = $type;
        $type = array_shift($extra_types);
    }
    if (!empty($this->alterEventListeners[$cid])) {
        $functions = [];
        foreach ($this->alterEventListeners[$cid] as $listener) {
            if (is_string($listener)) {
                $functions[] = substr($listener, 1);
            }
            else {
                $functions[] = get_class($listener[0]) . '::' . $listener[1];
            }
        }
        $message = 'The deprecated alter hook hook_' . $type . '_alter() is implemented in these locations: ' . implode(', ', $functions) . '.';
        @trigger_error($message . ' ' . $description, E_USER_DEPRECATED);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.