function _commerce_file_get_file_references in Commerce File 7
Retrieves a list of references to a file.
- - added access check bypass
See also
1 call to _commerce_file_get_file_references()
- commerce_file_file_download in ./
commerce_file.module - Implements hook_file_download().
File
- ./
commerce_file.module, line 1431 - Provides integration of file licenses with Commerce
Code
function _commerce_file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file', $allow_access_check = FALSE) {
$references = drupal_static(__FUNCTION__, array());
$fields = isset($field) ? array(
$field['field_name'] => $field,
) : field_info_fields();
$root_user = user_load(1);
foreach ($fields as $field_name => $file_field) {
if ((empty($field_type) || $file_field['type'] == $field_type) && !isset($references[$field_name])) {
// Get each time this file is used within a field.
$query = new EntityFieldQuery();
$query
->fieldCondition($file_field, 'fid', $file->fid)
->age($age);
// set tag to ensure that we get raw results not altered by the node access system
// @see http://drupal.org/node/1597378 - special tag added in Drupal 7.15
// @see http://drupal.org/node/997394#comment-5096664 - work-around being used below to support all versions
if (empty($allow_access_check)) {
$query
->addMetaData('account', $root_user);
}
$references[$field_name] = $query
->execute();
}
}
return isset($field) ? $references[$field['field_name']] : array_filter($references);
}