Currently FileField is only invoking the FileField module to check for file references when validating the contents of a Filefield. So, if a file isn't already used in a FileField, you can't add it to a FileField. If it did module_invoke_all to check for any file references from any module, people would be able to use files they uploaded by other means. FileField already uses module_invoke_all() when checking for file references before deleting a file, so it would only delete files that were no longer referenced by anything else.

See #441280: Editing node causes Referencing to the file used in the field is not allowed for discussion related to this issue.

Comments

+1 and thanks very much Adamo for pushing this along...and thanks quicksketch for following up with the code.

Now waiting for a fix that's better than the (much appreciated) hack at http://drupal.org/node/441280#30

Status:Active» Needs review
StatusFileSize
new2.45 KB

Here's the basic idea implemented in a patch. This introduces an implementation of hook_file_delete() for FileField, since it is necessary if a file were uploaded by FileField but then force-deleted by some other module (like IMCE). I haven't actually tested this in any capacity, just an idea of how we should go about this.

subing

As per Adamo's original post, I have the same use case with IMCE as all purpose file/image-browser in conjunction with File Field + File Field Sources.

Version:6.x-3.x-dev» 6.x-3.3
Status:Needs review» Fixed
StatusFileSize
new4.39 KB

This problem was a bit more complicated than I thought, but the patch in #2 had the right idea. There were a few caveats where FileField shouldn't be calling node_save() multiple times when a node is saved and file has been removed. Likewise, FileField should not be attempting to delete a file multiple times if field_file_delete($file, TRUE) is called to force the deletion of a file.

I've committed this patch so that we can get it in as part of the 3.4 release.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.