file_usage_list

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 file_usage_list(stdClass $file)

Determines where a file is used.

Parameters

$file A file object.

Return value

A nested array with usage data. The first level is keyed by module name, the second by object type and the third by the object id. The value of the third level contains the usage count.

See also

file_usage_add()

file_usage_delete()

Related topics

▾ 6 functions call file_usage_list()

FileDeleteTest::testInUse in modules/simpletest/tests/file.test
Tries deleting a file that is in use.
FileUsageTest::testGetUsage in modules/simpletest/tests/file.test
Tests file_usage_list().
file_delete in includes/file.inc
Delete a file and its database record.
file_field_delete_file in modules/file/file.field.inc
Decrements a file usage count and attempts to delete it.
file_managed_file_validate in modules/file/file.module
An #element_validate callback for the managed_file element.
system_cron in modules/system/system.module
Implements hook_cron().

Code

includes/file.inc, line 614

<?php
function file_usage_list(stdClass $file) {
  $result = db_select('file_usage', 'f')
    ->fields('f', array('module', 'type', 'id', 'count'))
    ->condition('fid', $file->fid)
    ->condition('count', 0, '>')
    ->execute();
  $references = array();
  foreach ($result as $usage) {
    $references[$usage->module][$usage->type][$usage->id] = $usage->count;
  }
  return $references;
}
?>