function hook_file_download_access_alter

Alter the access rules applied to a file download.

Entities that implement file management set the access rules for their individual files. Module may use this hook to create custom access rules for file downloads.

Parameters

$grants: An array of grants gathered by hook_file_download_access(). The array is keyed by the module that defines the entity type's access control; the values are Boolean grant responses for each module.

array $context: An associative array containing the following key-value pairs:

  • field: The field to which the file belongs.
  • entity: The entity which references the file.
  • file: The file entity that is being requested.

See also

hook_file_download_access().

1 invocation of hook_file_download_access_alter()
file_file_download in drupal/core/modules/file/file.module
Implements hook_file_download().

File

drupal/core/modules/file/file.api.php, line 251
Hooks for file module.

Code

function hook_file_download_access_alter(&$grants, $context) {

  // For our example module, we always enforce the rules set by node module.
  if (isset($grants['node'])) {
    $grants = array(
      'node' => $grants['node'],
    );
  }
}