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.
Comment | File | Size | Author |
---|---|---|---|
#4 | filefield_module_invoke_references.patch | 4.39 KB | quicksketch |
#2 | filefield_reference_any.patch | 2.45 KB | quicksketch |
Comments
Comment #1
boabjohn CreditAttribution: boabjohn commented+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
Comment #2
quicksketchHere'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.
Comment #3
Stephen Scholtz CreditAttribution: Stephen Scholtz commentedsubing
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.
Comment #4
quicksketchThis 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.