Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mavimo’s picture

mavimo’s picture

Patch to use with drush make:

projects[filefield_sources][subdir] = "contrib"
projects[filefield_sources][version] = 1.x-dev
projects[filefield_sources][patch][] = http://drupal.org/files/issues/filefield-sources-view-1170928-2.patch
bohz’s picture

HI, mavimo.
how difficult would it be to backport your patch to d6?
Ciao!

mavimo’s picture

@bohz: I don't use D6 version of fielfield_sources, but i think is not complex do it. I can try to backport into next days or, if you can start to backport it, ping me if you have some question ;)

Ciao!

scroogie’s picture

Looks nice. Subscribing.

quicksketch’s picture

This patch is similar to #904758: Views-based File Browser. Both have patches so I don't want to mark either duplicate. I'm not spending a lot of time on FileField Sources, so more testing/reviewing on these issues would be appreciated.

quicksketch’s picture

This is a good patch. I cleaned it up to work with the latest code and tidied up the JavaScript implementation a bit.

My plan is to include this only in the D7 version, which probably means we'll branch FileField Sources into 2.x branch with this feature and the option for paste from clipboard (#1768740: New Source: Paste from Clipboard).

dep85’s picture

With FileField Sources: v1.6 and Views: v3.5 I get message

Notice: Undefined property: view::$dom_id w template_preprocess_views_view() (linia 115 z ...\sites\all\modules\views\theme\theme.inc).

I fix that for now by adding
$view->dom_id = 0;
to theme_filefield_source_views_element function.
I'm know that $dom_id should be unique. But it works.

And I see that you still call file js/view.js what doesn't exist any more (views.inc - line:98)

karljohann’s picture

@quicksketch if I backport this to the D6 version, would you include it?

karljohann’s picture

presleyd’s picture

Rerolled the patch for version 1.7. Seems to be working for me with images. I'm going to mess around with the view some to see what all I can do with this.

presleyd’s picture

The issue with #8 is present I noticed. Steps to reproduce:

  1. Install File, Filefield Sources
  2. Add the patch in #11 to filefield sources
  3. Add a file field to a content type and select Views as Source within the field options
  4. Create new content of the type in 3 and upload a file or attach one via the view, the message will appear upon upload and again when the node is saved.
presleyd’s picture

Easy fix. The view should be rendered with the preview function instead of render. One word fix seems to have solved it. This feels better than the terribly hacky way I was thinking of incrementing dom_ids until I found an available one...

N20’s picture

I patched filefield_source with #13 but cant see any option to use a view for my file field. Are there any documentation or similar issue (cant find anything at the moment).

Thanks, N20

presleyd’s picture

On that field's settings page, what options are on the file field sources? Also, did you clear the cache?

N20’s picture

This is how settings for the filed look:
Settings

Cache was cleard.

presleyd’s picture

Version: 7.x-1.4 » 7.x-1.7
FileSize
11.37 KB

I can't reproduce this. I installed a clean version of the module on a fresh Drupal installation and then patched it after installation and everythig worked like a champ. It looks like this after patching.

This is against 1.7 now, I should have updated the version before...

N20’s picture

ok, this happens on a BOA platform with already a ton of modules in use. I will try to disable on after one and see what happens. Will report back - thanks so far!

N20’s picture

still the same on a fresh install. thats very strange..

N20’s picture

Ok, i found the problem. After downloading the module with drush, then patching it with
patch < filefield_sources-views_source-1170928-13.patch the file views.inc was'nt created in the source folder - but under the root module directory. I just moved it manually into the correct place and t-a-d-a!!

Thanks.

N20’s picture

There is also a Javascript file attached in views.inc wich not exist: modules/contrib/filefield_sources/js/views.js. This is called in views.inc around line 99.

$element['filefield_views'] = array(
    '#settings' => $settings,
    '#weight' => 100.5,
    '#theme' => 'filefield_source_views_element',
    '#filefield_source' => TRUE, // Required for proper theming.
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'filefield_sources') . '/js/views.js',
      ),
    ),
  );

That file is not even in the 7.x-1.7 tree.

cecrs’s picture

I applied the patch, and the view is awesome, thanks! However, as N20 noted, there is a missing js file. The reference is created in the patch (line 198), but the patch doesn't include the new file. (/js/views.js)

cecrs’s picture

I found the missing js file in the patch from comment #1, and included it in a re-roll of the patch.

presleyd’s picture

Is it needed? I was just going to remove the reference to it.

N20’s picture

So far i couldn't see that the missing file had any impact on the functionality. Seems like the views.js file attach the Image to the field on mouseklick on the button. But this works also without the file.

quicksketch’s picture

Hi guys, thanks for keeping up on this issue. My contrib modules are languishing a little bit while I'm spending a lot of time working on D8. There's a good chance we'll be seeing FileField Source-like integration in D8 directly as part of the WYSIWYG integration (#1932652: Add image uploading to WYSIWYGs through editor.module).

presleyd’s picture

@N20, I don't see it's point either, quicksketch must have taken it out for a reason in #7?

Here's the patch with the reference removed.

@quicksketch, that is very good news. I'll keep an eye on that discussion. I hope to get more involved with D8 testing when my current project clears up.

N20’s picture

Thanks for the patch presleyd. Now everything looks and works like it should.

cheers, N20

karljohann’s picture

I think the function was moved from views.js to filefield_sources.js. So removing the reference should suffice.

darrylh’s picture

FileSize
8.99 KB

Patch in #27 mostly works for me. The only problem I have is if you run into a validation rule - eg the chosen image dimensions are too small - the view gets a little mangled.

Manovra76’s picture

The patch have some problem after ajax call. The event.click sometime is lost:

file: field_source.js row 29

      $fileFieldElement.find('.filefield-source-view-button').click(Drupal.fileFieldSources.viewSourceButton);

I have add this code next row 29

      $fileFieldElement.ajaxComplete(
        function() {
          $fileFieldElement.find('.filefield-source-view-button').click(Drupal.fileFieldSources.viewSourceButton);
        }
      );

in this case if search something in form of use pagination, the add button is ok.

havran’s picture

#27 with #31 works perfect, thanks. Display view in modal windows (ctools) would be great too for this functionality.

MxRhd’s picture

I can't get the selection to work, I guess it's some typ eof JS error. I'm using 1.8 though, gonna try with 1.7 instead.

MxRhd’s picture

With 1.7 version it works in Seven theme, but not my custom theme built on Mothership.

With 1.8 version it does not work with either of the themes, even with the #31patch.

MxRhd’s picture

Also, the View-based selector does not have the option that File Attach has: Leave a copy of the file in the attach directory

I really really want this functionality, to choose from a view, and then to copy the file to a new directory.

Thanks for your hard work!

quicksketch’s picture

I really really want this functionality, to choose from a view, and then to copy the file to a new directory.

All files reused by FileField Sources *reuse* the file if it's already got an entry in the database. That includes the autocomplete, IMCE, and now the Views source. The file attach approach only copies the file because the file isn't yet managed by Drupal.

MxRhd’s picture

All files reused by FileField Sources *reuse* the file if it's already got an entry in the database. That includes the autocomplete, IMCE, and now the Views source. The file attach approach only copies the file because the file isn't yet managed by Drupal.

Ah ok. Makes sense.

I need it to copy the file though because of some advanced iamgecache text actions that uses the image entities to get node info from the image and print it on the image.

Do you have any ideas quicksketch on how I could theme the Attach to show the images with radiobuttons or what ever instead of a drop down list?

maxiorel’s picture

Maybe a stupid question - but how should I have to configure the view to have working the Add image button?

capellic’s picture

Issue summary: View changes

As someone who has really wanted to see the Media module be successful at local media management through a View (without feeling like I am implementing a best of a module that I don't understand), this is fantastic! The road to success wasn't so smooth for me, so let me share the steps I followed using FileField Sources 1.9

  1. Applied the patch in #27 above
  2. Two new files are created by this patch and they are put in the module root (filedfield_sources) instead of the proper subfolder.
  3. The "filefield_sources.views_default.inc" file should be in the "views" sub-folder (which you will need to create) so that it is here: filedfield_sources/views/filefield_sources.views_default.inc
  4. The "views.inc" file should be in the "sources" sub-folder so that it is here: filedfield_sources/views/views.inc
  5. Edit the field on which you have Filefield Sources enabled and:
    1. Select "Views-based selection" from the "Enabled sources" field in the "File sources" fieldset
    2. Select the view you want to use (Filefield Source View is what is provided by the patch) in the "View to search image" field in the "Views referenced options" fieldset which is in the "File sources" fieldset.

It should work now. If it doesn't, clear your browser and site cache.

Thanks to all who have worked on this, is it possible to role this into Dev?

capellic’s picture

I thought I'd document some of the features and great interface that this gives us.

Screenshot

  1. Out of the box, the View will show 2 rows of 5 images each. If there are more than 10 images, the pager will appear and it uses AJAX as does the file name search.
  2. Since this is a View, you can add the file name to the display
  3. When clicking on Add Image, the image ratio is validated against the minimum and maximum set on that file
  4. You are able to filter the View on path. So maybe you have a special image field for the Hero that has a very specific ratio and you are storing those images in files/hero. You can clone the View that comes with the module, add the file path as a filter so only images previously uploaded to the Hero image field will appear, thereby illuminated clutter caused by images that are the wrong ratio.

If you

presleyd’s picture

Version: 7.x-1.7 » 7.x-1.9

I didn't need to move the files when applying the patch with the -p1 switch. They ended up in the correct place already.
Incidentally I found this the other day that is basically the same functionality in a module. https://www.drupal.org/project/visual_select_file The only major difference is that it uses a modal. I actually do not like the modal as it is a pain in mobile and I need to turn my theme off in it but its nice to have a module that does this and is being maintained.

presleyd’s picture

Status: Needs review » Needs work

Hrmmm the javascript has issues in 1.9 ugh javascript

presleyd’s picture

I'll share what I know so far and maybe someone else can offer some info.

the code in #31 does seem to solve the paging issue. Since that wasn't clear to me when I first saw the post I'll clarify what is happening here. The js function we are adding to the page elements gets removed when the view calls up a different page via ajax. Adding the code in 31 makes it so that the function is reattached to the new elements upon ajaxcomplete. I'm not sure if there is a more elegant way to do this. Feels odd this way but I'll update the patch to include it.

Exposed filters do not work.. at first. Clicking the apply button provided by the view seems to try to validate the page (and setting the view to autosubmit causes nothing visible to happen). Once you press a pager link or select an image and attach it.. then the exposed filters work fine. This behavior is the same regardless of the change in #31 and I'm pretty sure this used to work so there may be some views issue at work here.

Steps to reproduce:
Download filefield_sources 7.x-1.9
add patch in #27
(optional) include code suggested in #31
Enable filefield_sources
Add Views as a source to a file field
Create a new node that contains that file field
Choose 'Select Existing' by the file field
Attempt to use exposed filter to search for a file by name (or add your own filter to the view if you like)

Chris Burge’s picture

Alternative option for using views as a source: http://www.drupal.org/project/filefield_sources_view

I've tested the module, and with the exception of a minor notice error, it tests successfully.