Having some functionality where the user could select multiple images in the media browser and implement a jquery slideshow would be pretty huge.

Can anyone help outline how something like that could be implemented with the media module? I've been familiarizing myself with the code and might like to take a whack at something like that.

Comments

JacobSingh’s picture

justinlevi’s picture

The Media Gallery looks really interesting. I'll definitely check that out.

Just a note that the URL for the rotating_banner project above is incorrect.
http://drupal.org/project/rotating_banner

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dmsmidt’s picture

Title:Media Browser - Multiple select with ctrl or shift click > Implement Jquery slideshow» Media Browser - Multiple select with ctrl or shift click
Status:Closed (fixed)» Active

I hope this is not a hijack ^_^ but I'm still really interested in a multiple select (and submit) option.
There are a lot of people searching for something like this. Media_Gallery offers this function but I don't want the Gallery.
I would like this option simply for a Media field with multiple items. Currently we have to click "Add new item" -> "Select media" etc. every time, this is very much work for 100 files.

With plupload I can upload a lot at once (although not through the node/edit form).
I'd like to be able to just select multiple files and them to the media field at once.

Or is this something for media_brower_plus ? (But it's a bit of an unclear mess for me..)
Isn't it possible to use the code of Media_Gallery?

james.elliott’s picture

Title:Media Browser - Multiple select with ctrl or shift click» Allow selecting of multiple media items for a multi value media field in the same dialog

Retitling to better represent the request.

slashrsm’s picture

I am trying to implement this, but I ran into a problem. My plan is to change Media's Multimedia asset field that way, that is supports this.

I was modifying js code that handles this things. I managed to recognise multivalue field and to send multiselect=true to media browser. That allows user to select multiple items, which are then returned to JS as an array.

My intial plan was to clone field items, which would allow me to add all assets from array. I would then just correct IDs of elements. It turned out that this does not work, as Drupal expects AJAX call for every item that is added.

Second idea was to call that AJAX call from JS code, to create all items I need. I was trying $(add_item_button).trigger('mousedown'), which actually adds another item, which is done asynchronously. The problem is, that I am not able to populate new items with assets from array, since that data is gone when AJAX call is completed.

Any suggestion how to solve that?

I also described my problem in forum: http://drupal.org/node/1138990

slashrsm’s picture

I've pushed my work to a sandbox: http://drupal.org/sandbox/slashrsm/1144920. Changes were made to 'javascript/media.js' only.

sanderjp’s picture

Hey slashrsm, I have a very ugly solution for this based on your trigger. I've used a timeout to wait for the new item to be added. I think it can be optimized alot, maybe a totaly different approach all together but I need this working in a week so I'll do it with this, for now.
I'm also not too experienced with the git yet, so I'll just post the code here that I made in media.js at the place you had the trigger function.
Download this js for the timeout function (doTimeout): jQuery doTimeout (jquery.ba-dotimeout.js) and add the following line to media.module (line 739) to load it:

$path . '/javascript/jquery.ba-dotimeout.js' => array('group' => JS_LIBRARY),

(more info on the function here: Ben Alman doTimeout)

Here's the code I made (yes quite silly, but it works! :P):

var a = 0;
var b = 0;
$('.field-add-more-submit', $(parent).parent()).trigger('mousedown');
$('body').ajaxComplete(function() {
a++;
if (a % 3 == 0 && b == 0) {
$('body').doTimeout( 300, function() {
var n = $('.field-multiple-table tr').last();
$('.media-widget .fid', n).val(mediaFiles[b].fid);
$('.media-widget .preview', n).html(mediaFiles[b].preview);
$('.media-widget .remove', n).show();
$('.field-add-more-submit').trigger('mousedown');
});
b++;
a = 0;
} else if (b > 0 && b < mediaFiles.length-1) {
$('body').doTimeout( 300, function() {
var n = $('.field-multiple-table tr').last();
$('.media-widget .fid', n).val(mediaFiles[b].fid);
$('.media-widget .preview', n).html(mediaFiles[b].preview);
$('.media-widget .remove', n).show();
if (b+1 < mediaFiles.length-1) {
$('.field-add-more-submit').trigger('mousedown');
}
});
b++;
}
});

The reason of the vars a and b is cos the first time you click 'add item', there are 3 ajax calls being made, so you need to wait till the third one to fill in the fields. Also the parents in the trigger don't work after the first one, so had to change that. Also had to change the n var to find the right tr element for some reason.

Let me know if it works for you, I haven't tested it yet on a clean install.

dmsmidt’s picture

It works a bit, thanks you two. I used the git version (#7) of media with your changes (#8).
(Though not very clear what to do and added the $path to line 759, not 739)

It only manages to add 3 items at once, also if I add 4 or more.
Side effect: The plupload module started to show up! Uploading multiple items worked, but sending them didn't.

Please if you have anymore progress let us know! Or how I can add more than 3 items at once. This is such an important feature.

wojtha’s picture

subscribing

dmsmidt’s picture

I edited the media.js code sample of sanderjp in #8, so that it works with unlimited items. It even works with plupload (uploading multiple files).

It's a very bad solution, because the process of adding items will increase per extra item (i*1000), and your computer needs to be powerful enough. But I needed a solution 2 weeks ago, so I'll take it for now.

$('.field-add-more-submit', $(parent).parent()).trigger('mousedown');   
var x = 1;    
$('body').doTimeout( i*1000, function() {
  var n = $('.field-multiple-table tr').last();
  $('.media-widget .fid', n).val(mediaFiles[x].fid);
  $('.media-widget .preview', n).html(mediaFiles[x].preview);
  $('.media-widget .remove', n).show();
  $('.field-add-more-submit').trigger('mousedown');
  x++;
});
pp’s picture

Hi, I made a module which resolve this issue.
http://drupal.org/sandbox/pp/1244926

If it is usable, I would like to create a patch to media modul.

idflood’s picture

I would love to see that integrated in media module instead of media_gallery. Being able to select/upload many medias at once and associate them to a node is definitely an expected behavior.

Any "official statement" about this?

dark11star’s picture

I tried this and It still only adds one of the selected images.

pp’s picture

dark11star: thanks, but just a question: Did you click "Select media" or "Add another item" button?
http://drupal.org/node/1244950

If you used "Select media" please try "Add another item" button instead of it!

Select media for one image, and add another item for add multiple images.

pp

artatum’s picture

Hi
Very interested by this feature, I'd like to download it but 'git clone etc' doesnt mean anything for me.
Is there a possiblity to simply get your module somewhere?

slashrsm’s picture

pp's project is a sandbox. Sandbox cannot have any releases you could download, so you must use git.

Check: http://drupal.org/project/1244926/git-instructions

dboulet’s picture

This would be a great feature to add. It looks like the maintainers are now focusing on the 2.x branch, we should probably try to produce a patch for that version.

hk0023’s picture

I don't know why the original media file selector widget still pops up instead of plupload. Is anyone else having this issue?

hk0023’s picture

Sorry, didn't read the comments above. Need to press the Add Media button instead of Select Media.

hk0023’s picture

StatusFileSize
new131.69 KB

However, I have another problem. Once I have uploaded one item, whenever I press the select media or the add another item again, the formatting of the popup widget is all weird.

dboulet’s picture

Hi hk0023, look at #1228790: Popup browser broken when using "Add another item" on multiple field, there’s a patch in that issue that fixes the last bug you mentioned.

hk0023’s picture

Thank you dboulet, everything's working fine now.

rickvug’s picture

Subscribe.

Dave Reid’s picture

Version:7.x-1.x-dev» 7.x-2.x-dev
Shawn DeArmond’s picture

#1186516: Allow multiple file upload via plupload on field widget. was marked as a duplicate, so I'm going to watch this issue now

Andrea C’s picture

Subscribe

sachbearbeiter’s picture

sub

kirilius’s picture

I would also like to see this feature becoming part of Media. I am trying to use Media not as a generic file organizer but as a means to manage multi-value images within a single node.

heyyo’s picture

Is the sandbox project in #12 working with media-7.x.2.x ?

rudiedirkx’s picture

Please don't use crappy 1990's plupload. Who the hell uses flash to upload files? It's almost 2012! HTML 5 is not new anymore.

Use the multiple attribute that ALL browsers (except IE 8-) support. And if the browser doesn't, do whatever you want: plupload, swfupload, other abominations.

pp’s picture

@rudiedirkx can you show me an example which I can select(not upload) multiple files?

pp

neurojavi’s picture

Subscribing

moonberry’s picture

subscribe

slashrsm’s picture

@moonberry, @neurojavi: Please do not post "subscribe" comments. Use "Follow" button instead.

More info: http://drupal.org/node/1306444

Dave Reid’s picture

Status:Active» Needs work
StatusFileSize
new747 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 951004-enable-multiselect.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Small patch enables the 'multiselect' flag to be set correctly in the Media browser. Pretty sure we have more work to do though.

Dave Reid’s picture

Marked #1489370: no multiupload in node image fields as a duplicate of this issue.

Bernsch’s picture

Hi All.

Currently i use this Modules:

  • Media 7.x-1.0
  • Media_Browser_plus 7.x-1.x-dev
  • Plupload integration 7.x-1.0-rc1
  • Media and Plupload connector (Sandbox project from user "pp" in #12)

I have my Contentype with image field and the Media Plupload file selector - upload is unlimited.

So.. when i create a node and come to my media image-field widget. I have the button "select media".
I click it and i become my media_browser_plus with plupload widget. OK. I use any pictures. When i click continue - no image thums are in my media-field widget. The Button "add another item" appears instead of "select media". When i klick this Button - its the same problem - no images thumbs.
It doesn't works :-( ...

Any here the same problem?

agentrickard’s picture

@Bernsch This patch is for 7.x.2, not 7.x.1. Please read the ticket details.

Bernsch’s picture

ok, i test this one with this modules:

  • Media 7.x-2.x-dev (from 19. April 2012) and the Patch from #36
  • Media_Browser_plus 7.x-2.x-dev (from 25. Feb 2012)
  • Plupload integration 7.x-1.x-dev (from 3. April 2012)
  • Media and Plupload connector (Sandbox project from user "pp" in #12)

I become a multiselect' flag. I have the button "select media".
I click it and i become my media_browser_plus with plupload widget. OK. I use any pictures. When i click continue - no image thums are in my media-field widget. The Button "add another item" appears instead of "select media". When i klick this Button - its the same problem - no images thumbs!

My question is: "What do i have to do to upload pictures as multiupload in a node image field" ?????
HELP ME PLEACE :-)!

Pomliane’s picture

Marked #1406310: Batch uploading from content edit form as a duplicate of this issue.

Pomliane’s picture

Marked #1489060: Plupload on the node edit page as a duplicate of this issue.

fangel’s picture

I'm working on a generic, stand-alone Media selector widget module that alters the 'add more' button to popup the Media Browser, and then adds the selected items to the field. It's still missing some work (doesn't work with a fixed >1 cardinality, not unlimited; doesn't work with single-value fields; removing media could have a better UX, ...).

In theory similar to what #6 and #8 is talking about, except with a custom ajax-callback and ajax-trigger so it no longer has to trigger mousedown events to fire the ajax event. The AJAX-callback alters the form and form-state to include the newly selected files.

I'll polish it up some more and then publish a sandbox tomorrow. (It currently needs a patched Media, because the Views based tabs doesn't support multiselected, yet)

slashrsm’s picture

Great! Can't wait to see this.

fangel’s picture

Okay, here's the first draft of the module I've done to add the functionality. Use the new 'Media Multiselect' widget for your fields. Any cardinality besides unlimited will result in a standard Media widget.

If you want Multiselect to work properly on the Views-based tabs, you need to patch Media with the patch provided by the module.

I does work kinda like the 'plupload integration' sandbox, except that it tries do less trickery like hiding the built in 'add more' button and replacing it with it's own, then triggering mousedown-events on the original, etc.
It could potentially be benifitial (as in, less code and trickery) to adapt the way that 'plupload integration' sends the new file ids over, except then you wouldn't know which were just added, so it can't add the 'ajax-new-content'-wrappers to enable show/hide effects.

http://drupal.org/sandbox/fangel/1652676

Andrea C’s picture

@fangel: do you think your module can also address this issue #1139266: specify directory path ?

fangel’s picture

Andrea C: Possibly, but I don't see why that shouldn't be solved in Media on a per-field basis.

Andrea C’s picture

@fangel: what people is afraid of is that, also if you set a folder for images uploaded in a field, after a while you can have thousand of files in one folder, and this is something not desirable from a site or system administrator.
It would be nice to keep all the images "attached" to one node in a dedicated subfolder of the folder choosed on a per-field basis.
The subfolder could be named using a token variable or date-time of node creation

fangel’s picture

Andrea C: I completely agree. But I believe it should be solved per-field not per-widget. And to support multi-select for inputs, you only need to change the widget, which is what my, and all the other attempts in this issue, have done.

Hence my "It should be solved in Media on a per-field basis".

Andrea C’s picture

Hi fangel,
Thanks for your time and answer.
I'm not so technical to understand how drupal works in deep.
I'm just one of those people who's not able to program on Drupal and wait for a solution to easily create an image gallery like the module Media_Gallery seems to do. The big problem is that all images are stored in the same folder.
I was just hoping your patch could be helpful for that.

fangel’s picture

Andrea C: No problem. In case you're interested (and it might help explain why the change should be preformed elsewhere), here's the 3-line explanation to the Drupal Field system.

There are fields. Fields is is what contains the data, and governs things like "which file extensions are allowed", "maximum files size allowed" etc. This is where "which folder should the images be stored in" is relevant.

Then there are widgets. Widgets controls how you input data into the field. So if you selected one file at a time, or multiple files at a time is determined by which widget you use. The input-method doesn't have any control over how the field chooses to store the data that is input.

Lastly there are formatters. Formatters is what takes the data from the field and displays it to the user. This is where you control stuff like 'what size to display the user', 'should clicking on the images open them in larger formats', etc.

So when I say that changing the directory the files is stored in should be done on a per-field basis - because fields is what stores the data - and not on a per-widget basis - because widgets only control how you input the data - I hope this now makes sense to you.

Andrea C’s picture

@fangel: Thanks again. Your disposability to explain is really appreciated.

Bernsch’s picture

#50 |Posted by Andrea C

...and wait for a solution to easily create an image gallery like the module Media_Gallery seems to do. The big problem is that all images are stored in the same folder.

Tip/Information:
The MODULE Media Gallery Extra provides additional features and improvements for the Media Gallery module. Also including patterns (tokens) and root directory in the file upload directory where gallery media will be stored. :-)

Andrea C’s picture

Thank You Bernsch, I will continue the discussion in the dedicated issue #1139266: specify directory path

Dave Reid’s picture

Marked #1692926: Media Browser not able to show multiple fids as a duplicate of this issue.

kiranch@vt.edu’s picture

Hi ,

Thank you for linking my post to this post but i was referring to the code in media/includes/media.browser.inc which i thought was not working as written in the comments. I do not want any additional dialogs in the UI but i am more interested in how backend can handle taking multiple "fids" and presenting them. It is already said the comments in the code i pasted below that if one or more files have been selected, the files can be handled.

I am pasting some of that code below. I thought i would mention it more clearly


// If one or more files have been selected, the browser interaction is now
  // complete. Return empty page content to the dialog which now needs to close,
  // but populate Drupal.settings with information about the selected files.
  if (isset($params['fid'])) {
  #  $fids = is_array($params['fid']) ? $params['fid'] : array($params['fid']);
    $fids=array(61,62);
    if (!is_numeric($fids[0])) {
      throw new Exception('Error selecting media, fid param is not an fid or an array of fids');
    }
    $files = file_load_multiple($fids);
    foreach ($files as $file) {
      media_browser_build_media_item($file);
    }
    $setting = array('media' => array('selectedMedia' => array_values($files)));
    drupal_add_js($setting, 'setting');
    return $output;
  }

Do you think the above code (which was written in 7.1.2 version) cant handle multiple files ?

Do you know if there are any changes in the -dev version that can handle multiple files in back-end?

Many Thanks,
Kiran.

juves’s picture

Hi

Is there a working solution with even basic functionality to this yet?

Jackinloadup’s picture

@juves See #45

fangel’s picture

I have a sandbox-module that implements most of the ideas I've had while thinking of how to solve the multi-select issue. It's located at http://drupal.org/sandbox/fangel/1652676.
Note: it works best with a patch applied, and only works for unlimited-cardinality fields.

slashrsm’s picture

There is also a list of modules that implement this on Plupload's integration project page. It would be better to have this implemented in Media, but should work until it is not.

ParisLiakos’s picture

@Andrea C : posted a patch here http://drupal.org/node/1776300#comment-6534426

rdworianyn’s picture

I am not sure if anyone has taken a look at this or not, but the module, plup is a very easy to use solution for multi-image uploading. It even has drag n' drop functionality built in. I have looked through all of the alternatives out there and either I'm missing something, or this is definitely the best option available.

Bernsch’s picture

Priority:Normal» Major

Such is the state regarding this issues in this contribution:
Allow selecting of multiple media items for a multi value media field in the same dialog

Which solution possibility should I pursue?
This one --> http://drupal.org/sandbox/fangel/1652676
Or there are other solving approaches or patches?

The multiupload problem in the media module is somehow a bit confusing...

ParisLiakos’s picture

http://drupal.org/sandbox/fangel/1652676 is quite good, i run it myself in a production site:)

Sk8erPeter’s picture

@Bernsch: I agree that this is a major priority issue.
Until a possible solution comes, I'm using Plup module: http://drupal.org/project/plup
I saw rdworianyn has already mentioned it, I agree with him, this is a great module, and provides a really comfortable UI: it provides the abilitiy to drag'n'drop the picture to its appropriate position when reordering, and shows a small but visible delete icon in the top right corner of every images, which is much nicer than the regular "Remove" buttons...
I think even Media module should learn from this module's great solutions. :))

Firstly I tried FileField Sources Plupload: http://drupal.org/project/filefield_sources_plupload, this is also a great module, but unfortunately one of my sites, it doesn't work correctly, the form doesn't get refreshed on the client side after uploading (maybe in connection with jQuery Update (the fresher jQuery) or Field group's accordions or I don't know: I couldn't trace the problem's source).

fangel’s picture

rootatwc: Sorry to bug you, but since you "admit" to using my sandbox module, do you think I could get you to help review the patch in this issue: #1848506: Media Browser parameters reset after AJAX pagination - it prevents multi-selecting in the Media Browser on anything but the first page. (I'll reroll the patch later today, since it failed testing because it couldn't apply)

ParisLiakos’s picture

@fangel i have seen the issue, but didnt bother much since patch was not applying. i will review it when it passes bot;)

Sk8erPeter’s picture

@fangel : I've just tried media_multiselect with Media 7.x-2.0-unstable7+2-dev, switched to "Media multiselect" widget and it doesn't work: after clicking "Add media" button, the Edit page just simply reloads without any JS error messages on the console... So it doesn't work at all, never has - at least for me. Any ideas?
(Btw. Epsa Crop module's "Manage image crops" link also disappears. :) )

fangel’s picture

Sk8erPeter: Create an issue on the sandbox issue-queue with info on browser, core+module versions and whatever else I need to try and replicate your problem, and I'll look into it..

Sk8erPeter’s picture

@fangel: I'm sorry, I just tested on a fresh Drupal install, and it does work.
But it seems like I just don't understand the purpose of your module. When I have "Media multiselect" widget enabled, the node edit looks like this:
http://i.imgur.com/DOTFV.png
when changing it back to "Media file selector", and adding one more image, it looks like this:
http://i.imgur.com/UtU6y.png
I don't understand why it's more comfortable to use your module... I don't really see the real differences. Maybe you could post some screenshots to your project's page or sg. like that. Thanks in advance.
I'm looking for a solution to upload ~50 or more images at once (or even a hundred), but this one doesn't seem to help me in this. :) (or I just missed something)

fangel’s picture

Sk8terPeter: The difference is that you can select more than one image at a time in the Media Browser (and if you have plupload + multiform enabled, you can upload more than one file at a time too).
So you don't have to press "Add media" N times, just once and then select N files and press "OK".

Sk8erPeter’s picture

@fangel : thanks, I'll try that with the earlier versions...
In the meantime, I realized that on the other Drupal site, where it DID work, I had only Media 7.x-1.2 installed... so no wonder it behaved differently than Media 7.x-2.0-unstable7+2-dev... So I reject what I said before :D, and maybe you should test your module with Media 7.x-2.0-unstable7+2-dev installed. Thanks in advance.

EDIT (after multiple edits):
OK, I tested this combo, and this is working perfectly:

Media 7.x-1.2 + plupload (7.x-1.x-dev [7.x-1.0+5-dev]) + multiform (7.x-1.x-dev) + media_multiselect + "Media multiselect" widget

Cool!!! Great work, fangel!
I'll test it also after upgrading to Media 2.x and plupload 7.x-2.x-dev, I'm curious... :)

EDIT 2:
it seems to work with media 7.x-2.0-unstable7+2-dev + media_multiselect 7.x + multiform 7.x-1.0 + plupload 7.x-1.0+5-dev too.

One really frustrating problem: when trying to upload multiple images at once, and trying to upload an unsupported file type too (which is e.g. not an image) like this:
http://i.imgur.com/DJ5Y9.png
after clicking "Next", I get an error message that the given file could not be uploaded, and all the images are "lost" even when I tried to upload like 30 images at once. This is not too good, the unsupported file should just not be uploaded, and that's all, but this should not affect the rest of the files.
Look:
http://i.imgur.com/qdgmp.png

Is this problem in connection with your widget or with Plupload module?

Bernsch’s picture

Hi Sk8erPeter,
I have the test carried out with the same modules as you.

I become a multiselect' flag. I have the button "select media".
I click it and i become my media_browser with plupload widget. OK. I use multible pictures. I use the alt an title tags. When i click continue - no image thumbs displayed. The button "select media" is displayed again. Although the pictures are uploaded but not displayed in my article! I can see the images in content/media!
I test in firefox, chrome and IE9.
hm...i dont understand this..

Sk8erPeter’s picture

@Bernsch: the truth is that it only works for me on fresh Drupal installs. I tried to make it work on two other sites, and the "Add media" button did nothing at all, and there were no JavaScript errors either. On one of the sites, I have multiple nested field groups, I don't know if it's related at all.
Can you also test it on a fresh Drupal site?
And can you post a screenshot of the error? I don't know if fangel will see it, but maybe we should continue this discussion about his module on the Issues for Media Multiselect page. :)

fangel’s picture

Yes, please do take any issues to the proper issue queue. If you can find the specific modules that breaks my module, please list them there. But yes, everything is developed on a clean git-checkout of Drupal, Media, File Entity, etc - and then tested on our production site with ~50 or so contrib modules...

Sk8erPeter’s picture

In the meantime, I realized that the problem I mentioned in #68 is related to the new ImageField Tokens 7.x-1.x-dev.
When disabling ImageField Tokens, Media multiselect works correctly!
So I created an issue related to this problem:
http://drupal.org/node/1859976#comment-6816610

mglaman’s picture

Issue summary:View changes
Status:Needs work» Needs review
StatusFileSize
new3.25 KB
FAILED: [[SimpleTest]]: [MySQL] 970 pass(es), 2 fail(s), and 6 exception(s).
[ View ]

Here is a patch I whipped up to bake in support for multiselect within the media browser on fields. This is against the latest HEAD which implements the newly formatted Media field widget. The Media Multiselect sandbox was broken by the field widget change - see #2216273: Latest media changes break the multiselect.

One of the issues is how media_attach_file() checks $_POST data. I don't know how much I like the fact my patch manipulated $_POST info, but unless Media is updated to stash data in $form_state, it's the only way.

Status:Needs review» Needs work

The last submitted patch, 77: allow_selecting_of-951004-77.patch, failed testing.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 77: allow_selecting_of-951004-77.patch, failed testing.

The last submitted patch, 36: 951004-enable-multiselect.patch, failed testing.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 77: allow_selecting_of-951004-77.patch, failed testing.

mcrittenden’s picture

  1. +++ b/includes/media.fields.inc
    @@ -283,6 +284,20 @@ function media_field_widget_process($element, &$form_state, $form) {
    +  $upload_name_prefix = implode('_', $element['#parents']) . '_';
    +  $upload_name = $upload_name_prefix . $element['#file_upload_delta'];
    +  if (!empty($_POST['media'][$upload_name])) {

    A code comment for these lines with an example of $upload_name and $element['#parents'] might be helpful - seems kind of magic-ish just from the code.

  2. +++ b/includes/media.fields.inc
    @@ -283,6 +284,20 @@ function media_field_widget_process($element, &$form_state, $form) {
    +      $_POST['media'][$upload_name_prefix . ($element['#file_upload_delta'] + $i)] = $files[$i];
    +      $element[] = $element[$element['#file_upload_delta']];

    Same here - comments explaining why would be helpful, otherwise I could see this being misunderstood and broken in the future.

  3. +++ b/js/media.js
    @@ -71,19 +71,29 @@ Drupal.media.openBrowser = function (event) {
    +    var mediaFileValue;

    Maybe mediaFileFid would be more descriptive?

mglaman’s picture

Thanks, mcrittenden. I'll update with comments. Essentially Media is checking $_POST['media'][FIELDNAME_LANGCODE_CARDINALITY]. Those tidbits reconstruct that and add the additional required field name values so they can be processed.

Like I said, it'd be better if only had to manipulate $form_state to add them in, but the field value callback pulls directly from $_POST.

Status:Needs work» Needs review
shortspoken’s picture

Thanks @mglaman, I just tested the patch with Media 7.x-2.0-alpha3+98-dev and its working! Didn't test it with latest dev though. Anyone?

ahillio’s picture

Wow, patch from #77 worked on Media 2.0-alpha4+11-dev thanks :)

ahillio’s picture

Patch from #77 indeed is using plupload for uploading to image fields, it uploads and saves them successfully.

Should this load a multiform for editing all the new file entities instead of going straight back to node edit form?? This would make it much easier to add alt tags or taxonomy terms to the images, rather than having to do them one-by-one from the node edit form.

Thanks again!

mglaman’s picture

firestk, media_multiselect worked the same way. It inserts directly. The same as when adding an individual item. You have to go back and edit.

And I promise to re-roll patch w/comments. The patch only failed because test bot was having issues.

ergophobe’s picture

Just to add that while it might be nice to have multiform as firstek suggests, I think this patch already is such a huge advance that I would love to see it committed as is and have multiform support added as a separate issue.

Thanks mglaman - this is so great.

ergophobe’s picture

Confirming that I applied this to the 7.x-2.0-alpha4 and the current dev (30 Nov 2014) and the patch applies fine.

When I select the Media Browser widget, voila! Perfect. It gives me everything I want and have been hoping for from the Media module forever.

mglaman, you're a saint. This simplifies things so much over every other solution I've tried and for me works perfectly out of the box.

desarrollo2.0’s picture

StatusFileSize
new27.26 KB

#77 works perfect with the following configuration:

media-2.x-dev
media_bulk_upload (and multiform module)
plupload module and library
file or image field with "media browser" widget and "number of values" set to "unlimited"

Thanks!

Ravenight’s picture

I confirm this works as well.

applied this to the 7.x-2.0-alpha4

YAY!

rcodina’s picture

I also confirm that patch #77 works for me too. My environment:

Media (media) 7.x-2.0-alpha4+11-dev
Plupload integration module (plupload) 7.x-1.7
Multiple forms (multiform) 7.x-1.1

Also I have:
-Module "Media Bulk Upload" enabled
-Image field with: a) Unlimited values b) Media Browser widget
-No need of module Media Multiselect

Maybe we can mark this issue as RTBC, couldn't we? I think is a key feature for this module so it should be commited ASAP.

Keep up the good job @mglaman Thanks!

rcodina’s picture

Status:Needs review» Reviewed & tested by the community

I think this issue should be RTBC.

mglaman’s picture

Status:Reviewed & tested by the community» Needs review
StatusFileSize
new3.48 KB
FAILED: [[SimpleTest]]: [MySQL] 970 pass(es), 2 fail(s), and 6 exception(s).
[ View ]

Thanks everyone for the great feedback! I hate to do it, but I need to roll this back from RTBC to CNR because I never addressed the comment issues in #84

Here is updated patch with comments detailing the reconstruction of the field name, langcode, and delta (ex: field_myfield_und_0) to allow the multiselect magic to work.

Also,

Maybe mediaFileFid would be more descriptive?

I think mediaFileValue makes more sense, as it can be a map or single value.

jeffschuler’s picture

#97 is working great for me!
Thanks for all of this hard work. :)

mcrittenden’s picture

Status:Needs review» Reviewed & tested by the community

Thanks!

ergophobe’s picture

Just updated to Panopoly 1.14 and updated the Media module to alpha4+11dev and mglaman's patch is still working great.

I have got a pretty nasty setup here in terms of testing - Panopoly + Organic Groups + running with Zurb Foundation (though Responsive Bartik for admin). I've had a lot of issues wth stability and conflicts with other solutions. This patch is very solid so far and I have maybe a couple hundred automated Selenium tests and as near as I can tell, this patch is not causing any issues.

It would be great to see this committed!

Rob C’s picture

RTBC for me. Tested this with a couple sites now that used to work with media_multiselect (sandbox). Switching this just works great.

slippast’s picture

Okay, so I just installed this patch. It's a great. However, if you have Image Javascript Crop module enabled this functionality is broken. What happens is that when you are creating new content the image/file fields only show a text area and a button labeled 'attach'.

I used patch #15 from the following thread to fix the problem and get Image Javascript Crop working again: https://www.drupal.org/node/2196011

To mglaman: patch #97 works very well. What a massive improvement to the Media module! I've wanted this functionality for several years now. Thank you so much!

The last submitted patch, 77: allow_selecting_of-951004-77.patch, failed testing.

Status:Reviewed & tested by the community» Needs work

The last submitted patch, 97: allow_selecting_of-951004-97.patch, failed testing.

mglaman’s picture

Assigned:Unassigned» mglaman

Updating patch to fix tests...

mglaman’s picture

Status:Needs work» Needs review
StatusFileSize
new3.93 KB
FAILED: [[SimpleTest]]: [MySQL] 971 pass(es), 1 fail(s), and 6 exception(s).
[ View ]
new462 bytes

Here's first attempt to fix tests, at least one fixed. Other test randomly fails locally still, but not repeatably :/4

I'll keep digging, but it seems

$nid = $this->attachNodeFile($test_file, $field_name, $type_name);
...
$this->drupalPost("node/$nid/edit", $edit, t('Save'));
...
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers));

$out has the proper field values in the HTML, but it doesn't seem to be saving correctly in tests.. but fine everywhere else.

Status:Needs review» Needs work

The last submitted patch, 106: allow_selecting_of-951004-106.patch, failed testing.

ergophobe’s picture

Thanks for sticking with this mglaman

mori’s picture

BIG HUGS & THANKS for the patch! Would be great to have it applied in the next dev-version.

my setup:
Media (media) 7.x-2.0-alpha4+14-dev (2014-Dec-17)
Plupload integration module (plupload) 7.x-1.7
Multiple forms (multiform) 7.x-1.1
File Entity 7.x-2.0-beta1+12-dev

Also I have:
-Module "Media Bulk Upload" enabled
-Image field with: a) Unlimited values b) Media Browser widget

sense-design’s picture

#106 works great for me

The last submitted patch, 106: allow_selecting_of-951004-106.patch, failed testing.

dmsmidt’s picture

#106 really great!

mglaman’s picture

Update: been busy with holidays and work. Dedicating sprint weekend to getting this patch to pass tests so we have an epic win on Media & D7

sense-design’s picture

@mglaman: Would be great

mglaman’s picture

Kind of at a loss.

$_POST in media_field_widget_process_multiple() during test

    [media] => Array
        (
            [zrjx9ohl_und_0] => 1
        )

Form state snippet after _form_builder_handle_input_element() set's values.

    [zrjx9ohl] => Array
        (
            [und] => Array
                (
                    [1] => Array
                        (
                            [fid] => 0
                            [display] => 1
                            [description] =>
                            [_weight] => 0
                            [attach_button] => Attach
                            [upload] =>
                            [remove_button] => Remove
                        )

                    [0] => Array
                        (
                            [_weight] => 0
                            [fid] => 1
                            [display] => 1
                            [description] =>
                        )

                )

        )

The form's setting the value, but when the test reloads the node it isn't set for unlimited cardinality fields. Will pick this up later.

mori’s picture

With File Entity 7.x-2.0-beta1+13-dev and patched Media (media) 7.x-2.0-alpha4+14-dev (2014-Dec-17) the patch does not work anymore.
You can upload multiple files but only the 1st one is attached.

mori’s picture

Another usability issue I´ve spotted is that the uploaded files are then attached in a "reversed order" -> first uploaded file is attached last.
In my opinion the order should be the same as in the upload dialog.

mglaman’s picture

mori, thanks for heads up! Maybe that's my issue - changes in File Entity. I'll compare what our product is using + patch against latests in both modules.

I'll also investigate #118.

ergophobe’s picture

I don't think recent changes to File Entity are the issue. Your patch is still working great for me with recent versions of everything

- File Entity 7.x-2.0-beta1+12-dev (2014-12-03)
- Media 7.x-2.0-alpha4+11-dev (2014-11-19)
- CTools 7.x-1.6-rc1 (2014-12-19) with patch 2119357-6_0.patch #2119357: Undefined index in ctools_argument_entity_id_context()
- Panels 7.x-3.4+19-dev (2014-12-23)
- Panelizer 7.x-3.1+59-dev (2014-06-03)
- the full Panopoly stack

The only thing I have that is older than mori's setup is Media. I'm not sure how much changed between alpha4+11 and alpha4+14

I have a pretty extensive set of Selenium tests that I run on each upgrade and they are all still passing fine.

stijn.blomme’s picture

I can confirm the patch from #106 works on the latest media dev release.
- media 7.x-2.0-alpha4+23-dev
- file_entity 7.x-2.0-beta1
- plupload 7.x-1.7
- multiform 7.x-1.1

-> Do not forget to enable the media_bulk_upload sub module that comes bundled with media!

dtarc’s picture

StatusFileSize
new4.7 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/media/modules/media_bulk_upload/media_bulk_upload.module.
[ View ]

I have been using the patch from #106 but file uploads have been failing for larger files. Investigating more, tnightingale discovered that file upload chunking was not happening. Presumably this is because neither the plupload module nor the patch to media sets the default #plupload_settings as defined in the plupload module README.

I'm not sure if this should be the responsibility of media or plupload. I have opened an issue on the plupload module queue to check (#2420749: Documented default for chunk_size does not match value in code).

In the meantime, here's the patch from #106 adjusted to also include setting the chunk_size setting to 20mb.

Any thoughts on whether this should go into media_bulk_upload or plupload? I suppose the chunk size as well as some of the other #plupload_settings could be made into variables in media_bulk_upload. This might be easiest for sites using plupload with media.

dtarc’s picture

StatusFileSize
new4.7 KB
FAILED: [[SimpleTest]]: [MySQL] 988 pass(es), 1 fail(s), and 6 exception(s).
[ View ]

Re-rolling the patch in #122 to fix a syntax error.

dtarc’s picture

Status:Needs work» Needs review

The last submitted patch, 122: media_allow_selecting_of-951004-122.patch, failed testing.

Status:Needs review» Needs work

The last submitted patch, 123: media_allow_selecting_of-951004-123.patch, failed testing.

mglaman’s picture

Assigned:mglaman» Unassigned

dtarc can you please post interdiffs of your patches versus what I had.

+++ b/modules/media_bulk_upload/media_bulk_upload.module
@@ -6,6 +6,20 @@
/**
+ * Implements hook_entity_info_alter().
+ */
+function media_bulk_upload_element_info_alter(&$type){
+  if (isset($type['plupload'])) {
+    if (!isset($type['plupload']['#plupload_settings'])) {
+      $type['plupload']['#plupload_settings'] = array();
+    }
+    if (!isset($type['plupload']['#plupload_settings']['chunk_size'])) {
+      $type['plupload']['#plupload_settings']['chunk_size'] = '20mb';
+    }
+  }
+}
+
+/**

I'm hiding the last patch that contains this. While I dig, I think it should be part of it's own issue and not part of this patch/functionality. That portion should go into media_bulk_upload, but I feel it's an issue outside of this one's scope (and possibly a true bug that needs fixing.) We haven't experienced, and we support 100MB+ uploads.

You could have an unlimited cardinality field without bulk upload. This simply allows multiple selection from the library. That's the goal of this patch, IMO.

I hid the other patches, just to keep this organized (not to be rude/disrespectful.) Willing to discuss in IRC as well!

ergophobe’s picture

To answer dtarc's question, I think his patch should be part of plupload, not part of this patch.

The plupload module gets used in conjunction with other modules, not just Media and so thsi problem should be fixed once, in onc place, rather than in every module that invokes plupload.

Not to mention that many, many people would really love to see Matt's work get committed, though obviously one of us needs to find the time to figure out why the automated tests are failing.

dtarc’s picture

I can post an interdiff later today. The only difference was the function shown, media_bulk_upload_element_info_alter().

I don't want to hold up this patch with an indirectly related issue and agree that this really should be fixed in plupload.

Uploads started failing once file size got close to 1GB. 500MB files worked fine. I'm not sure at exactly which size file upload started failing--but we determined that the upload failures were due to file upload chunking not happening. It could be that failures are related to fastcgi, which we are using. However once the chunk_size setting was included, file uploads have been successful.

I just wanted to post this here as well since media users will have the expectation that this patch allows plupload with all its expected functionality. Also I wasn't sure if this could affect the failing tests.

I'll follow up in the plupload module issue.

ergophobe’s picture

I added that issue as a related issue bother here and there so it shows up in the "related" sidebar.

dtarc’s picture

I think this is indeed a bug for plupload (even if just a documentation bug) and I have uploaded the linked issue in the plupload module queue.

I didn't mean to derail this issue as I'm also looking forward to seeing the work committed soon. Please disregard the patches in #122 and #123. I thought this issue was more about plupload integration in general than about using it for multiple files. The use case we need plupload for is handling large file upload via chunking, so I suppose that's where my focus was.

I think once this is committed, many media users will add plupload, so hopefully something gets resolved in the plupload queue. It was a confusing issue to sort out and I don't think our configuration is uncommon. Jacking up the php.ini vars seems to be a common solution to load issues on drupal sites.

In the meantime, this is how we are getting around the issue:

/**
* Implementation of hook_library_alter()
*/
function mymodule_library_alter(&$libraries, $module) {
  if ('plupload' == $module && isset($libraries['plupload'])) {
    if (isset($libraries['plupload']['js'][0]['data']['plupload']['_default'])) {
      $libraries['plupload']['js'][0]['data']['plupload']['_default']['chunk_size'] = '16mb';
    }
  }
}

Again, sorry for the tangent.

mglaman’s picture

Issue summary:View changes

dtarc, no problem! Multiple selection, bulk uploading, it's all a large system that is rough. Appreciate bringing it to attention, nonetheless, as it'll affect our product.

To recap, though: This patch is failing because multiple select is failing - not upload. The unlimited cardinality field is failing read the POST being sent from modal, even though it works manually and through debugging simpletest. (See #116)

Still trying to figure out why. Debugging simpletest isn't easy, because the process forks off on submit and I can't debug it :(

mglaman’s picture

Issue summary:View changes

Changing back issue summary.. comment changed it.

uniquename’s picture

I fixed #118 with a simple mediaFiles.reverse(); in media.js line 77.

izmeez’s picture

@uniquename Do you have a modified patch and interdiff to offer?