5 * Hooks for file module.
9 * Control download access to files.
11 * The hook is typically implemented to limit access based on the entity the
12 * file is referenced, e.g., only users with access to a node should be allowed
13 * to download files attached to that node.
15 * @param array $file_item
16 * The array of information about the file to check access for.
18 * The type of $entity; for example, 'node' or 'user'.
20 * The $entity to which $file is referenced.
23 * TRUE is access should be allowed by this entity or FALSE if denied. Note
24 * that denial may be overridden by another entity controller, making this
25 * grant permissive rather than restrictive.
27 * @see hook_field_access().
29 function hook_file_download_access($file_item, $entity_type, $entity) {
30 if ($entity_type == 'node') {
31 return node_access('view', $entity);
36 * Alter the access rules applied to a file download.
38 * Entities that implement file management set the access rules for their
39 * individual files. Module may use this hook to create custom access rules
42 * @see hook_file_download_access().
45 * An array of grants gathered by hook_file_download_access(). The array is
46 * keyed by the module that defines the entity type's access control; the
47 * values are Boolean grant responses for each module.
48 * @param array $file_item
49 * The array of information about the file to alter access for.
51 * The type of $entity; for example, 'node' or 'user'.
53 * The $entity to which $file is referenced.
55 function hook_file_download_access_alter(&$grants, $file_item, $entity_type, $entity) {
56 // For our example module, we always enforce the rules set by node module.
57 if (isset($grants['node'])) {
58 $grants = array('node' => $grants['node']);