Retrieves a list of references to a file.
$file: A file object.
$field: (optional) A field array to be used for this check. If given, limits the reference check to the given field.
$age: (optional) A constant that specifies which references to count. Use FIELD_LOAD_REVISION to retrieve all references within all revisions or FIELD_LOAD_CURRENT to retrieve references only in the current revisions.
$field_type: (optional) The name of a field type. If given, limits the reference check to fields of the given type.
An integer value.
function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file') {
$references = drupal_static(__FUNCTION__, array());
$fields = isset($field) ? array(
$field['field_name'] => $field,
) : field_info_fields();
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);
$references[$field_name] = $query
->execute();
}
}
return isset($field) ? $references[$field['field_name']] : array_filter($references);
}