function file_get_file_references

Retrieves a list of references to a file.

Parameters

$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.

Return value

An integer value.

Related topics

1 call to file_get_file_references()
file_file_download in drupal/modules/file/file.module
Implements hook_file_download().

File

drupal/modules/file/file.module, line 1074
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

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);
}