I have a cck FileField attached to a content type. When I remove a file from a node I want to remove the reference to the file but keep the file on the server. The reason for this is because we use IMCE on the site as well and other items may reference the image. Do you know if this is possibe?
+1
A:
From looking at the code in FileField_delete here:
function field_file_delete($file, $force = FALSE) {
$file = (object)$file;
// If any module returns a value from the reference hook, the
// file will not be deleted from Drupal, but file_delete will
// return a populated array that tests as TRUE.
if (!$force && $references = module_invoke_all('file_references', $file)) {
$references = array_filter($references); // only keep positive values
if (!empty($references)) {
return $references;
}
}
It looks like hook_file_references may come to your aid. However I can't see many modules (other than filefield) that use this hook.
It would be possible for you to write your own module to track specific fields and implement your own hook_file_references. You could for example track specific cck values and query them when the hook is called.
Jeremy French
2010-01-20 14:20:26
If you're using something like http://drupal.org/project/filefield_sources and have the file associated with other nodes, then the file won't be deleted until the last node that references the file is removed.
jhedstrom
2010-01-20 18:49:19