Repeatable: Always
Steps to repeat:
0. Dependencies on modules: Plupload (currently using 7.x-1.7), Multiple forms (currently using 7.x-1.1)
1. Adding a field with the type "Image" and the widget "Media browser"
2. Set "Number of values" at least to 2
3. Adding N (N > 2) images into this field
Expected Results:
- Upload in media browser popin:
bar.jpg (fid: 21)
baz.jpg (fid: 22)
foo.jpg (fid: 23)
- Files order after submit, in field data result (sorry for my bad English):
bar.jpg (fid: 21)
baz.jpg (fid: 22)
foo.jpg (fid: 23)
Actual Results:
- Upload in media browser popin:
bar.jpg (fid: 21)
baz.jpg (fid: 22)
foo.jpg (fid: 23)
- Files order after submit, in field data result:
foo.jpg (fid: 23)
baz.jpg (fid: 22)
bar.jpg (fid: 21)
I don't really know if this behaviour can be assimilated to a bug or a misunderstanding from me.
So I created a feature request and I will explain my use case.
When I add several images to upload, they are added in alphabetically order in the admin popin.
I want to keep this order.
After few tests I realized that the order is preserved on file_save (fid keep same order than filename).
But the files order in the field data result wrapper is loss. More specifically, the order is reverted.
I found out that its come from the re-indexing deltas in the function media_field_widget_submit, from file media.fields.inc
// Re-index deltas after removing empty items.
$submitted_values = array_values($submitted_values);
Is it possible to configure this behaviour from the field UI form ? (Checkbox allowing DESC or ASC order for the uploaded files)
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | media-upload_sorting-2474639-10.patch | 1.03 KB | scottalan |
| #4 | media-upload_sorting-2474639-4.patch | 575 bytes | scottalan |
| #2 | media-7-x-2-0-alpha4--fix-files-order-on-submit.patch | 709 bytes | anfor |
Comments
Comment #1
nikolino commentedI've the same problem.
Have you find a solution?
Thanks
Comment #2
anfor commentedYes I found a solution, here the patch I used.
However I didn't test the last Media release (7.x-2.0-beta1).
Comment #3
anfor commentedComment #4
scottalan commentedUploading a new patch with a different take. Needed this for our use case.
With this you can then do something like:
Comment #5
andrej galuf commentedI actually prefer the solution in #4, as it allows for more complex sorting solutions.
Works as advertised.
Comment #6
joseph.olstadpatch #4 still applies cleanly, would have to add some documentation if we added it.
Looks simple enough, just thinking that something like this should be documented somewhere, so included with the patch (say a patch to the Readme.txt or a new book page to the media documentation here: say under recipes (suggested location for this type of documentation))
Comment #7
joseph.olstadThis will likely get some attention soon.
First In First Out /first displayed/ first in the list.
seems most logical for usability.
Comment #9
joseph.olstadThanks @anfor, works like a charm.
Comment #10
scottalan commentedEnded up needing to meet different sorting requirements. Wanted to post my solution here since this is where I posted the first patch I submitted.
We had a request that newly uploaded images get added to the top of the list vs the bottom of the list. In order to do this I needed to add a different alter hook as I didn't have all the information needed to determine what files were new and what files existed previously.
I've added a comment above the hook to better explain.
Comment #11
joseph.olstad@scottalan , great stuff, can we please open a new issue for your patch? That way this one can stay 'fixed'
just add a link to the new issue like
[#N0DEID]