diff --git a/entity.module b/entity.module index 7ec5f13..9712d9e 100644 --- a/entity.module +++ b/entity.module @@ -1094,6 +1094,7 @@ function _entity_info_add_metadata_callbacks(&$entity_info) { // Set access callbacks. $entity_info['node']['access callback'] = 'entity_metadata_no_hook_node_access'; $entity_info['user']['access callback'] = 'entity_metadata_user_access'; + $entity_info['file']['access callback'] = 'entity_metadata_file_access'; // CRUD function callbacks. $entity_info['node']['creation callback'] = 'entity_metadata_create_node'; diff --git a/modules/callbacks.inc b/modules/callbacks.inc index 11e07bf..4d74bb0 100644 --- a/modules/callbacks.inc +++ b/modules/callbacks.inc @@ -611,6 +611,24 @@ function entity_metadata_taxonomy_access($op, $entity = NULL, $account = NULL, $ } /** + * Access callback for file entities. + */ +function entity_metadata_file_access($op, $entity = NULL, $account = NULL, $entity_type) { + if ($op == 'view' && isset($entity)) { + // Invoke hook_file_download() to obtain access information. + foreach (module_implements('file_download') as $module) { + $result = module_invoke($module, 'file_download', $entity->uri); + if ($result == -1) { + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + + +/** * Callback to determine access for properties which are fields. */ function entity_metadata_field_access_callback($op, $name, $entity = NULL, $account = NULL, $entity_type) {