Unless I am missing something, currently File Field Sources can only reference an existing file provided that it is registered in the file_usage table. This covers files uploaded through Core fields and via IMCE, but it prevents the user to reference a file uploaded through File Entity or Media browsers, because such files are registered only in the file_managed table (they are not “in use”). If I try to reference such a file using File Field Sources, I get the error: “The file used in the … field may not be referenced”.

Would it be possible to support all the files in the file_managed table, whether they are in use or not?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

It's a security precaution, because otherwise attaching a file and then deleting the node would delete the file. This behavior isn't likely to change.

lifepillar’s picture

I see, the check is in the File module…

My problem is that I'd like to upload several files in advance, and attach them to nodes only at a later time, or at no time at all (for instance, favicon.png and images for blocks). IMCE would allow me to do that, but I want to upload more than one file at a time (btw, I do not like the fact that IMCE “uses” the files it uploads). The only alternative I can think of is to create a special node type T and attach these files to nodes of type T, using Plupload for multiple uploads. Then, File Field Sources allows me to reference them if I need them. Not the ideal solution for me: I would really like to use File Entity (but not Media), which makes files full entities distinct from content, allows me to replace a file without changing fid, and so on…

lifepillar’s picture

So, I may reformulate this feature request as follows: would it be possible to add an option to bypass that validation?

serjas’s picture

To remove restriction , in sources/refernces.inc ,change this
$files = filefield_source_reference_get_files($filename, $field);

to

$files = filefield_source_reference_get_files($filename);

DamienMcKenna’s picture

Issue summary: View changes

I ran into this problem whereby a huge file was attached to a field but an error occurred during node submission and the save action failed - it had already moved the file into place but the file wasn't listed in a field so couldn't then be referenced again in a new record; the only solution was to re-upload the files.

jenlampton’s picture

I keep running into this too. For particularly large files (or large sets of files) my editors like to upload them ahead of time using the File Entity interface, then they are confused when "Reference existing" can't find the existing file.

This patch provides a third option in the autocomplete settings that allows any file in the managed_file table to be referenced.