file_get_file_references
function file_get_file_references
file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file')
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
File
- modules/file/file.module, line 1072
- 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); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!file!file.module/function/file_get_file_references/7.x