drupal文件参照函数:hook_file_references

modules/system/system.api.php, 1172行

版本
7
hook_file_references($file)

报告一个文件被一个模块引用多少次.

这个钩子被调用来确定如果文件正在使用中。多个模块可参照相同的文件,并防止一个删除的文件所使用的另一种钩子被调用.

同时参考

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.

相关主题

Hooks
Allow modules to interact with the Drupal core.

代码

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


同步内容