Download & Extend

The number of parameters that can be passed by reference to drupal_alter() has changed (affects hook_file_download_access_alter() in Drupal 7 core)

Project: 
Drupal core
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. It is removed in Drupal 8, which will only accept a maximum of two context parameters.

If you have more than two context parameters that need to be passed to alter hooks, the following method is recommended in Drupal 7 and required in Drupal 8:

<?php
 
// 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,
  );
 
drupal_alter('mymodule_data', $data, $entity, $context);
?>
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