You are here

public function ModuleHandler::alterDeprecated in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/ModuleHandler.php \Drupal\Core\Extension\ModuleHandler::alterDeprecated()

Passes alterable variables to deprecated hook_TYPE_alter() implementations.

This method triggers an E_USER_DEPRECATED error if any implementations of the alter hook are found. It is otherwise identical to alter().

See the documentation for alter() for more details.

Parameters

string $description: Helpful text describing what to do instead of implementing this alter hook.

string|array $type: A string describing the type of the alterable $data. 'form', 'links', 'node_content', and so on are several examples. Alternatively can be an array, in which case hook_TYPE_alter() is invoked for each value in the array, ordered first by module, and then for each module, in the order of values in $type. For example, when Form API is using $this->alter() to execute both hook_form_alter() and hook_form_FORM_ID_alter() implementations, it passes array('form', 'form_' . $form_id) for $type.

mixed $data: The variable that will be passed to hook_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.

mixed $context1: (optional) An additional variable that is passed by reference.

mixed $context2: (optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.

Overrides ModuleHandlerInterface::alterDeprecated

See also

\Drupal\Core\Extension\ModuleHandlerInterface::alter()

https://www.drupal.org/core/deprecation#how-hook

File

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

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->alterFunctions.
  $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->alterFunctions[$cid])) {
    $message = 'The deprecated alter hook hook_' . $type . '_alter() is implemented in these functions: ' . implode(', ', $this->alterFunctions[$cid]) . '.';
    @trigger_error($message . ' ' . $description, E_USER_DEPRECATED);
  }
}