Implements hook_file_download_access().
function file_module_test_file_download_access($field, EntityInterface $entity, File $file) {
$instance = field_info_instance($entity
->entityType(), $field['field_name'], $entity
->bundle());
// Allow the file to be downloaded only if the given arguments are correct.
// If any are wrong, $instance will be NULL.
if (empty($instance)) {
return FALSE;
}
}