From 98509c1af65fb88ce81a2f148a85d44092f22bf0 Mon Sep 17 00:00:00 2001 From: catch Date: Sun, 22 Jan 2012 11:01:19 +0900 Subject: [PATCH] Issue #1245220 by plach, dpolant, xjm, bfroehle: Fixed file_file_download() passed bogus to field_access(). --- core/modules/file/file.module | 2 +- core/modules/file/tests/file_module_test.module | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 68204aa7a5f..c9518074221 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -172,7 +172,7 @@ function file_file_download($uri, $field_type = 'file') { // Find the field item with the matching URI. foreach ($field_items as $field_item) { if ($field_item['uri'] == $uri) { - $field = $field_item; + $field = field_info_field($field_name); break; } } diff --git a/core/modules/file/tests/file_module_test.module b/core/modules/file/tests/file_module_test.module index 2fdadb8638f..48ba87b4d91 100644 --- a/core/modules/file/tests/file_module_test.module +++ b/core/modules/file/tests/file_module_test.module @@ -69,3 +69,16 @@ function file_module_test_form_submit($form, &$form_state) { } drupal_set_message(t('The file id is %fid.', array('%fid' => $fid))); } + +/** + * Implements hook_file_download_access(). + */ +function file_module_test_file_download_access($field, $entity_type, $entity) { + list(,, $bundle) = entity_extract_ids($entity_type, $entity); + $instance = field_info_instance($entity_type, $field['field_name'], $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; + } +}