function hook_file_download_access

Control download access to files.

The hook is typically implemented to limit access based on the entity that references the file; for example, only users with access to a node should be allowed to download files attached to that node.

Parameters

$field: The field to which the file belongs.

Drupal\Core\Entity\EntityInterface $entity: The entity which references the file.

Drupal\file\File $file: The file entity that is being requested.

Return value

TRUE is access should be allowed by this entity or FALSE if denied. Note that denial may be overridden by another entity controller, making this grant permissive rather than restrictive.

See also

hook_field_access().

4 functions implement hook_file_download_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_file_download_access in drupal/core/modules/comment/comment.module
Implements hook_file_download_access().
file_module_test_file_download_access in drupal/core/modules/file/tests/file_module_test.module
Implements hook_file_download_access().
node_file_download_access in drupal/core/modules/node/node.module
Implements hook_file_download_access().
user_file_download_access in drupal/core/modules/user/user.module
Implements hook_file_download_access().
1 invocation of hook_file_download_access()
file_file_download in drupal/core/modules/file/file.module
Implements hook_file_download().

File

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

Code

function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\File $file) {
  if ($entity
    ->entityType() == 'node') {
    return node_access('view', $entity);
  }
}