? filefield_sources-730578.patch
Index: sources/reference.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield_sources/sources/reference.inc,v
retrieving revision 1.6
diff -u -p -r1.6 reference.inc
--- sources/reference.inc	9 Aug 2010 04:11:49 -0000	1.6
+++ sources/reference.inc	12 Aug 2010 11:19:48 -0000
@@ -84,6 +84,46 @@ function filefield_source_reference_sett
       '#type' => 'radios',
       '#default_value' => empty($field['filefield_source_autocomplete']) ? '0' : '1', 
     );
+    
+    if (module_exists('views')) {
+      $views = array('--' => '--');
+      $all_views = views_get_all_views();
+      foreach ($all_views as $view) {
+        // Only 'node' views that have fields will work for our purpose.
+        if ($view->base_table == 'files' && !empty($view->display['default']->display_options['fields'])) {
+          if ($view->type == 'Default') {
+            $views[t('Default Views')][$view->name] = $view->name;
+          }
+          else {
+            $views[t('Existing Views')][$view->name] = $view->name;
+          }
+        }
+      }
+
+      $return['sources_reference']['advanced'] = array(
+         '#type' => 'fieldset',
+         '#title' => t('Advanced - Files that can be referenced (View)'),
+         '#collapsible' => TRUE,
+         '#collapsed' => !isset($field['filefield_source_advanced_view']) || $field['filefield_source_advanced_view'] == '--',
+       );
+      if (count($views) > 1) {
+        $return['sources_reference']['advanced']['filefield_source_advanced_view'] = array(
+          '#type' => 'select',
+          '#title' => t('View used to select the files'),
+          '#options' => $views,
+          '#default_value' => isset($field['filefield_source_advanced_view']) ? $field['filefield_source_advanced_view'] : '--',
+          '#description' => t('<p>Choose the "Views module" view that selects the nodes that can be referenced.<br />Note:</p>') .
+            t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
+        );
+      }
+      else {
+        $return['sources_reference']['advanced']['filefield_source_no_view_help'] = array(
+          '#value' => t('<p>The list of nodes that can be referenced can be based on a "Views module" view but no appropriate views were found. <br />Note:</p>') .
+            t('<ul><li>Only views that have fields will work for this purpose.</li><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
+        );
+      }
+    }
+  
   }
   elseif ($op == 'save') {
     $return[] = 'filefield_source_autocomplete';
