Change record status: 
Project: 
Introduced in branch: 
7.x, 8.x
Introduced in version: 
7.22
Description: 

When Drupal 7 was first released, drupal_alter() accepted a maximum of two context parameters that could be passed along to hook implementations (in addition to the primary data parameter). However, to allow for the fact that some older code was still attempting to pass additional parameters along (including invocations of hook_file_download_access_alter() in Drupal core), this restriction has been relaxed in Drupal 7.22 so that an additional, third context parameter can be passed. This means that hooks such as hook_file_download_access_alter() will now begin working as designed.

The third context parameter is being introduced to Drupal 7 for backwards-compatibility reasons only and should be considered immediately deprecated; do not use it for new Drupal 7 code.

If you have more than two context parameters that need to be passed to alter hooks, the following method is recommended:

  // There are three pieces of contextual information ($entity, $field, and
  // $instance) that we want to pass to implementations of
  // hook_mymodule_data_alter(), so put two of them together in the last
  // context parameter.
  $context = array(
    'field' => $field,
    'instance' => $instance,
    // To pass a reference to an array, use the reference operator.
    'some_array' => &$some_array,
  );
  drupal_alter('mymodule_data', $data, $entity, $context);

The equivalent method in Drupal 8, ModuleHandlerInterface::alter(), only accepts a maximum of two context parameters.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done