hook_file_references($file)
drupal/modules/system/system.api.php, line 1115
Report the number of times a file is referenced by a module.
This hook is called to determine if a files is in use. Multiple modules may be referencing the same file and to prevent one from deleting a file used by another this hook is called.
@see file_delete() @see upload_file_references()
$file The file object being checked for references.
If the module uses this file return an array with the module name as the key and the value the number of times the file is used.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
function hook_file_references($file) {
// If upload.module is still using a file, do not let other modules delete it.
$count = db_query('SELECT COUNT(*) FROM {upload} WHERE fid = :fid', array(':fid' => $file->fid))->fetchField();
if ($count) {
// Return the name of the module and how many references it has to the file.
return array('upload' => $count);
}
}