diff --git a/entity.module b/entity.module index 432d469..de1f038 100644 --- a/entity.module +++ b/entity.module @@ -942,6 +942,7 @@ function entity_entity_info_alter(&$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 74ef308..cf6d080 100644 --- a/modules/callbacks.inc +++ b/modules/callbacks.inc @@ -605,6 +605,22 @@ 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) { + // Invoke hook_file_download() to obtain access information. + foreach (module_implements('file_download') as $module) { + $function = $module . '_file_download'; + $result = $function($entity->uri); + if ($result == -1) { + return FALSE; + } + } + return TRUE; +} + + +/** * Callback to determine access for properties which are fields. */ function entity_metadata_field_access_callback($op, $name, $entity = NULL, $account = NULL, $entity_type) {