I needed to be able to reference all images, even if they are initially uploaded to another field, so I adapted filefield_source_reference_get_files (reference.inc -line 175) as follows: add $field = NULL; after the function declaration.

Is there a better way of handling this? Or is there some hidden settings i'm missing?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

There aren't any settings yet, but I agree that referencing any file from any field would be a good option to have. It should be an option in the future once we have a place to put these settings.

sinasalek’s picture

+!
If i understand correct The following code allows only files uploaded by filefield fields. as long as i know Drupal6's uploads files already have FID, so what's the reason for this limitation?
Thanks

function filefield_source_reference_get_files($filename, $field = NULL) {
  if (!isset($field)) {
    foreach (content_fields() as $field) {
      if ($field['type'] == 'filefield') {
        $fields[] = $field;
      }
    }
  }
  else {
    $fields = array($field);
  }

  $files = array();
  foreach ($fields as $field) {
    $db_info = content_database_info($field);
    $result = db_query("SELECT f.* FROM {" . $db_info['table'] . "} c INNER JOIN {files} f ON c." . $db_info['columns']['fid']['column'] . " = f.fid WHERE f.filename LIKE '%s%%' AND status = 1", $filename);
    //$result = db_query("SELECT f.* FROM {files} f WHERE f.filename LIKE '%s%%' AND status = 1", $filename);
    while ($file = db_fetch_object($result)) {
      $files[$file->fid] = $file;
    }
  }
   
  return $files;
}
quicksketch’s picture

If i understand correct The following code allows only files uploaded by filefield fields. as long as i know Drupal6's uploads files already have FID, so what's the reason for this limitation?

We will not be able to support any file. It needs to be uploaded by a FileField somewhere. The reason for this is that FileField is the only module that keeps a reference count explaining where a file has been used. Say we referenced a file provided by upload module or a user's profile picture. Then that node were deleted that contained the reference. Now suddenly the file would be deleted even if it were in use in another location. This has been corrected in D7 with the new File API, but it will never be possible in Drupal 6.

sinasalek’s picture

Thanks for the respond,
I see, so it's Drupal's limitation actually. Is there any workaround,patch for this? or is there any discussion for Drupal6 going on?

ezra-g’s picture

Title: Reference all files » Reference all filefield files
FileSize
13.3 KB

With quicksketch's endorsement of this feature in #1, I started working on implementing this and the related configurable options for FileField_sources. I need to refactor some of the code I've written before it's fit to post here, but my approach was to make it possible for each available source to expose it's own configuration options that get aggregated into filefiled_sources' implementation of hook_widget_settings_alter() . In the attached screenshot, you can see the widget settings and the "Referencable Fields" options. I hope to post a patch later this week.

I posted in this issue rather than #436174: Configuration Options because the feature described here is my objective, and configurable options seem like a requirement for that. I could split these into two patches if quicksketch prefers.

ezra-g’s picture

Status: Active » Needs review
FileSize
2.97 KB

Thought I hit preview...Here's the patch.

ezra-g’s picture

Indeed I had hit preview...

This above patch makes it possible to configure which fields are referenceable. It depends on the patch at http://drupal.org/node/436174#comment-2288226 .

What's particularly exciting about referencing uploads from other fields is that it allows users to implement images as their own distinct content type with a single value ImageField, but still embed those images inside of other content.

Here's what it looks like:

ezra-g’s picture

FileSize
2.97 KB

This minor re-roll corrects the spelling of "Referenceable" in the interface.

Sorry for the mail flurry.

quicksketch’s picture

ezra-g! Looking fantastic. Just what I'd been hoping to do also. I'll get some free time to review your patches shortly, in the mean time keep plowing ahead. :-)

ezra-g’s picture

Thanks for the positive feedback!

Just wanted to mention that I've written a lengthy tutorial including filefield_sources, and that this module will likely come up in a presentation at DrupalcampNYC this Saturday. I'd love to be able to tell folks, "This is available now" :).

mrfelton’s picture

nothing to add... just tracking the issue so that I know when it has been committed. Great work @ezra-g

David Lesieur’s picture

Tried the patch. Did not find the settings. Got the following PHP message: warning: Missing argument 3 for filefield_source_reference_settings() in sites\all\modules\filefield_sources\sources\reference.inc on line 66. Apparently the $widget argument is never set.

ezra-g’s picture

@David Lesieur Did you apply the dependency patch at http://drupal.org/node/436174#comment-2288226 as mentioned in #7? If so, can you describe how to generate the error you're experiencing?

David Lesieur’s picture

Oops, that's right, I had missed that. I now get the settings and things seems to be working as expected. Sorry for the noise!

However, I'm getting this message after adding a filefield: warning: Invalid argument supplied for foreach() in includes\form.inc on line 1205. This only happens when no referenceable fields have been checked.

David Lesieur’s picture

Status: Needs review » Needs work

Another issue with the patch is that the "FileField Sources" widget settings are displayed for all types of fields, not just FileFields.

onesimpleman’s picture

The patch works , but there is no way to get rid of the default Upload option.
I am working on a project where the only option needed is Remote URL.

Is there a work around to change the default option to Remote URL . I can hide the upload option with CSS.

ezra-g’s picture

Status: Needs work » Needs review
FileSize
2.95 KB

I found that the most recent patch no longer applied. I will upload a revised patch shortly at #436174: Configuration Options to address the feedback raised by David Lesieur in #15.

@David Lesieur: I'm not able to reproduce the error message you mentioned in #14. Could you let us know if it happens with the latest set of patches in this and the above mentioned issue? Thanks for the testing!

ezra-g’s picture

Status: Needs review » Closed (duplicate)

I'm marking this as a duplicate of #436174: Configuration Options. Please see http://drupal.org/node/436174#comment-2430824 for the reasoning and latest patch for this feature. Thanks!

TCRobbert’s picture

I was looking into this functionality. And found it here. Checking the other issue though it seems that this functionality never made it. Any chance we will be able to see this in the future. Or am I seriously overseeing something.

kpaxman’s picture

Component: Code » General

I would like the same functionality in the D7 module. I see a lot of talk around this that seems to have been abandoned years ago. Is there a plan for this somewhere I'm missing?

kpaxman’s picture

Version: 6.x-1.x-dev » 7.x-1.8
Status: Closed (duplicate) » Needs work
FileSize
2.68 KB

In absence of other options, I created this patch against 7.x-1.8 which gives a seemingly working "search all file fields" option, if nothing else.

Alan D.’s picture

Issue summary: View changes
Status: Needs work » Needs review

I've been using this for a small project where I have done all of the data entry ~60 pages, ~20 shared files, and no issues. Great enhancement imho, I never realised that this was limited till I actually needed to use it for the very first time in a real project (developer not a content author), and instantly hit this limitation on the first file! ;)

Liam Morland’s picture

Version: 7.x-1.8 » 7.x-1.x-dev
FileSize
2.6 KB

Reroll.

dman’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the patch. Works perfectly for me today.
I'd long forgotten that I'd been using a patched version on a much older site. Funny this great small feature has been left out for such a long time.

My task today is to let an editor upload (optionally) different images for use in thumb/teaser/banner/promo and full views of an article, for various artistic reasons. So in the first instance, that's a number of filefields for them. Though I anticipate that MOST of the time they will actually be re-using the same pic, so don't see the need to force them to upload the same thing thrice, at all.

filefield_sources was my obvious go-to, but I tripped at the first step until I came and found this was still an issue.

bgilhome’s picture

I've added an incremental feature/patch to list a thumbnail alongside autocomplete results - option in widget settings to select an image style (or none).

GiorgosK’s picture

#23 works as designed
please commit

@bgihome while this is a great feature this issue is not about this
so I suggest you open up a new issue and post your patch to be considered

GiorgosK’s picture

#25 patch is irrelevant to this issue
as already mentioned should be included in a new issue

ttkaminski’s picture

FYI, I created a new issue #2415393: Reference autocomplete thumbnails for patch in #25.

Alan D.’s picture

It is an awesome feature that I'd love to see get in. Anyone recently reviewed this (against dev)?

One of the few default patches left that we add to our client sites, so we nearly have a completely patch free default system 4 years into D7 life cycle... :)

DamienMcKenna’s picture

DamienMcKenna’s picture

DamienMcKenna’s picture

  • profak committed 295c548 on 7.x-1.x
    Issue #454982 by Liam Morland: Reference all filefield files
    
profak’s picture

Status: Reviewed & tested by the community » Fixed

#23 works fine and pushed to 7.x-1.x.

Thanks everyone!

profak’s picture

Status: Fixed » Closed (fixed)

In 7.x-1.10.

Liam Morland’s picture

Thanks.

Issues should be left at status "Fixed". After 2 weeks with no comments, they will change automatically to "Closed (fixed)".

profak’s picture

@Liam Morland

Thank you for your point!

jenlampton’s picture

Alan D.’s picture

#2557461: [UX] Options for "Search all file fields" are unclear

@jenlampton
if you wrap # issue number in sq brackets, this embeds the issue title and status, as above. [#number]

Removes the need to navigate to the thread to see if there is anything there of interest :)