A similar issue was started quite some time ago for the CCK project (actually, I think it was started in the Views issues, then moved to CCK for integration with Views).
I'm surprised it still hasn't made it into CCK in D7. I figured perhaps this issue should be mentioned for core, since most of CCK ended up in there.
This is about integration with the Views Module. We can sort results in views randomly at the node level (for instance, sorting content of type Gallery into a random order). However, we cannot sort at the field level (for instance, sorting the images in each Gallery's image field randomly).
My use case is that I have a bunch of short 'tips' on certain subjects. It would be ugly to create a separate piece of content for each one, so I have them all housed in a single piece of content, as separate entries in a text field. I would like to create a view that will display a single random entry.
I can create a view that will only display the first entry, or the last entry, because the field entries can be reversed under Multiple Field Settings in Configure Field. It would be great if the entries could be randomized.
Please see a similar issue in the CCK module: http://drupal.org/node/439230
Comment | File | Size | Author |
---|---|---|---|
#86 | 1190900-86.patch | 2.02 KB | _utsavsharma |
| |||
#86 | interdiff_77-86.txt | 977 bytes | _utsavsharma |
#85 | 1190900-nr-bot.txt | 2.11 KB | needs-review-queue-bot |
#77 | 1190900-77.patch | 2.02 KB | anmolgoyal74 |
#73 | views-random-sort-1190900-64.patch | 2.29 KB | Tobias März |
Comments
Comment #1
george.plescan CreditAttribution: george.plescan commentedI tried to convert the patch done for CCK and I'm not sure of the end result. I have no errors, but I think it is not working.
Basically this is what I modified : views_handler_field_field.inc in views\modules\field.
Here I found similar lines to the ones in the CCK patch.
I added the $form['multiple_random'] on line @505 and changed the incompatible values from 6.x to the ones from $form['delta_reversed'], because they are quite the same.
Also I registered the multiple random option at @320 like :
$options['multiple_random'] = array(
'default' => FALSE,
);
so I don't get a "not found" error.
Everything is fine so far but I don't know what to do with the actual function and where to put it ...
I added the random function somewhere at @645 but after some tests it doesn't seem to work, it just show the first item.
Hope we get some help for this considering that before the patch was for CCK 6.x and now I modified Views in 7.x ...
Comment #2
dddave CreditAttribution: dddave commentedDevelopment happens in dev. ;)
Comment #3
baby.hack CreditAttribution: baby.hack commentedHehe, thanx dddave. I suppose any feature requests should be for a dev version, rather than simply pointing out that the feature isn't in the current version?
Comment #4
yched CreditAttribution: yched commentedViews now handles the integration of Field API data.
Comment #5
kclarkson CreditAttribution: kclarkson commentedI too would love this feature. Random image field for example.
+1
Comment #6
dawehnerUncheck "Display all values in the same row" in the field settings in views and you get a new result per imagefield.
Once you have this you can use the global: random sort.
Comment #7
kclarkson CreditAttribution: kclarkson commented@dereine,
thanks for the quick reply.
Here is what I am trying to do in views. I have nodes that have multiple images. In the teaser version I would like to have just one of the images show, but have the images randomly change. At the same time I would like to sort each block node by date so the random piece would have to be in the field vs. sorting the nodes randomly.
I tried your suggestion but did not see that option in the image field settings.
Something similar to this module but within views would be cool as a feature: http://drupal.org/project/field_multiple_limit
Comment #9
sammyd56 CreditAttribution: sammyd56 commentedRe-opening as I also can't find that option and have a similar use-case to #7. Pretty sure we're not the only ones looking for random sorting at a field level...
Comment #10
dawehnerThis configuration is on the field itself. You can see the configuration on the screenshot linked in the issue.
Comment #11
sammyd56 CreditAttribution: sammyd56 commented@dereine Got it! Thanks for your help :)
Comment #12
andjules CreditAttribution: andjules commentedre-opening; unless I'm misunderstanding, the solution doesn't really address the original request, as I understand it.
Assumptions:
When - as suggested above - I deselect "Display all values in the same row", that node now appears multiple times (once for each of the values in the mutiple-value-field) in the returned view. Adding the global random to the sort seems to just randomize the order in which those repeated nodes appear. Adding 'distinct' to the SQL settings has no effect.
What intuitively makes sense is under the field settings > multiple field settings > to add a 'randomize' button (frankly, I can't see how this isn't a more obvious/common choice vs the current ' first and last only' checkbox, for which I struggle to imagine a use case(?))
Comment #13
Oniryck CreditAttribution: Oniryck commentedHello,
I'm really interested in this feature. I don't understand why it isn't in the main module yet. I wrote the attached patch to implement this feature. Could it be considered to be added in Views as a feature ? Maybe this patch is the wrong way of doing this, or maybe there's already a way to do this, in which cases I'd really like to know more about it :)
I tried to do this with an external module too, but overriding the handlers of all fields doesn't sound like a good idea !
I'm a beginner in Drupal and this my first contribution, but I'm willing to know more if anybody has a better idea. Thank you for your understanding ^^
Comment #14
Jack3rror CreditAttribution: Jack3rror commentedThis patch worked for me, as I would like to shuffle the multiple field.
Thx. I wonder if I could see a module based on this patch, to learn how to contribute to drupal.
Comment #15
risharde CreditAttribution: risharde commentedRequesting this as part of main module, we really need to have the ability to randomize on a multi field...
Comment #16
dawehnerPlease patch against the root directory of views, so for example the testbot can have a look at the patch and do its automatic testing
Some nitpicking: You introduced some empty lines with just spaces in your patch.
Set to needs review so the testbot jumps in.
Comment #18
broncomania CreditAttribution: broncomania commented#13: ViewsMultipleFieldRandomize.patch queued for re-testing.
Comment #20
philsward CreditAttribution: philsward commentedWould love to see this completed. I've been waiting close to a year to see this implemented... It would also greatly increase the functionality of Views Slideshow. I was able to get this accomplished with Views on D6 but I can't remember which site I did it to, to go back and see what I did to make it work... I could have sworn I either used the delta or fid as either an argument or relationship, but neither seem to do anything right with Views 3
In my use case situation, I've created a content type "Front Page Image". I create ONE node to upload all of my images to. I want to only show ONE image out of the fields but have it show up randomly. It would go hand-in-hand with views slideshow by allowing a person to create a single node for all of their banner images to rotate through randomly. It would also expose all images for a gallery of multiple nodes, to show up randomly instead of just the first image in the gallery. It would also grant flexibility to a text field where a person wants to only show one text field at a time, but have the order show up randomly. Think of a quote node where the text field contains the actual quotes. Put a block on the home page and have it randomly rotate through the multiple fields on visit to the home page. It eliminates the need for multiple nodes.
Idealy, there needs to either be a checkbox for "random" in the Multiple Field Settings or allow the starting from: to accept random as an input instead of just the fid/delta number.
Just my $0.02
Comment #21
philsward CreditAttribution: philsward commentedGrr...!! I KNEW there was a way to do it!!
1) Simply uncheck the Display All Values in the Same Row
2) Set the sort to Global: Random
3) Set the PAGER to Display a specified number of items with that number being 1
DONE
Been jacking with this for 2.5 hrs...
Dear Devs:
Please make this a bit more straight forward / easier! : )
Comment #22
aspilicious CreditAttribution: aspilicious commentedDear philsward, feel free to make a patch that makes this more straight forward.
Comment #23
philsward CreditAttribution: philsward commented@aspilicious If I knew how to code, It would have already been done and I wouldn't have previously posted a front end "work around"... Sorry, not trying to be rude, just get frustrated when devs tell me to "throw some code at it" after I point out a trouble area. If I knew how to fix it, I wouldn't be crying out for help and if I had the money, I would just pay someone else to fix it for me.
Comment #24
ls CreditAttribution: ls commentedI'm sorry, but this is not a solution to the problem that the OP described.
Because I ran into the same problem I created a patch to add a random order checkbox to the multiple value field.
Comment #25
ls CreditAttribution: ls commentedAgain for patch testing.
Comment #27
ls CreditAttribution: ls commentedTrying again.
Comment #29
ls CreditAttribution: ls commentedComment #31
GuyPaddock CreditAttribution: GuyPaddock commentedThis patch worked for me. Not sure why patch felt the line was improperly terminated; it actually ended up applying okay.
Comment #32
aspilicious CreditAttribution: aspilicious commentedYour editor needs configuration, let the editor convert tabs into 2 spaces, and strip trailing line endings
Comment #33
yul63 CreditAttribution: yul63 commented@philsward
Thank you, you just saved me 2 hours :)
Comment #34
kclarkson CreditAttribution: kclarkson commentedDoes this patch need to be rewritten to pass before we test it?
Comment #35
philipz CreditAttribution: philipz commentedThis one should pass.
Comment #36
grozozo CreditAttribution: grozozo commentedI just applied the #35 patch and it's working perfectly. Thx philipz and all of you for this.
I think that this function should be included in view. It's a little thing but save hours of work. So I pass the status to need review.
Comment #37
srgk CreditAttribution: srgk commenteda very needed feature, this patch worked beautifully
Comment #38
maxplus CreditAttribution: maxplus commentedGreat patch,
works perfect, exactly what I needed!
Many thanks
Comment #39
PhilY@philipz
Thanks a lot for patch at #35, it works under Views 7.x-3.7
Comment #40
Summit CreditAttribution: Summit commentedHi, this works great, setting it to RTBC, ok?
Greetings, Martijn
Comment #41
Homotechsual CreditAttribution: Homotechsual commentedAny idea if/when this will be committed to Views 7/D8 Core? It's a nice feature which really solidifies Views handling of multivalue fields
Comment #42
wingalingadingdong CreditAttribution: wingalingadingdong commentedConfirmed Patch #35 works as intended
Comment #43
Neograph734Is there any update on this? It's such a small feature, but there are so many possible use cases... Would love to see this in Views Core.
Comment #44
jrreid CreditAttribution: jrreid commentedYep. I will see if I have a chance this week to port it to D8, and hopefully then we can get it also included in D7. Its indeed a very helpful and needed feature.
Comment #45
dawehnerWe should at least use the drupal default code style here, but is it just me that this is is quite some code to get a random array? isn't there at least something like array_rand?
Comment #46
philipz CreditAttribution: philipz commented@dawehner you're absolutely right. I guess I've re-rolled the patch without much thinking ;)
Comment #47
Neograph734I can confirm this still works as expected.
Comment #48
Homotechsual CreditAttribution: Homotechsual commentedCan also confirm that it works as intended still.
Comment #49
litwol CreditAttribution: litwol commentedWorks as intended. i hope this can get into --dev soon.
Comment #50
Neograph734@dawehner, you think you could commit this to views?
Comment #51
reallyordinary CreditAttribution: reallyordinary commentedThis stopped working for me after the most recent Views security update. Tried patching again to no effect. Tried patching against most recent dev version, also no effect.
EDIT: Oops - disregard; re-applying patch DID work - but the "Random" checkbox in the view had lost its setting and needed to be clicked back on again.
Comment #53
petiar CreditAttribution: petiar commentedI have also successfully applied this patch, so what can I do to help to get it in the .dev version of Views?
Thanks.
Comment #54
Jej CreditAttribution: Jej commented#46 tested successfully too. I use random sort on an image field formatted as colobox gallery, works as expected.
Thanks for this 17 lines patch, quite efficient.
I wish I would to see it in Views.
Comment #55
shortspoken CreditAttribution: shortspoken commented#46 works as expected. Thanks @philipz. Please get this committed into views!
Comment #56
colanWe've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.
If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.
We apologize for the trouble, and appreciate your patience.
Comment #57
Neograph734Re-uploading as requested. Simplytest.me applied the patch, so hopefully it passes. Credits to philipz for the original patch.
Comment #58
Neograph734Re-marking RTBC from #47 as test passed.
Comment #60
colanThanks!
Comment #61
Neograph734I believe this should do for Drupal 8.
Comment #62
Neograph734Oops, copied the comment number in the last one... Same patch different name.
Comment #65
Neograph734Added the delta_random option to the yml file.
Comment #71
bwoods CreditAttribution: bwoods as a volunteer commentedThis patch generally works with 8.4, but it needs to be applied to EntityField.php, instead of Field.php, which is being depreciated.
There are a few small syntax changes as well - using brackets instead of array calls, but it still works. Thanks for creating this patch!
Comment #73
Tobias März CreditAttribution: Tobias März as a volunteer commentedCreated patch to work with Drupal 8.5.
Comment #76
BrightBoldThe patch in #73 appears to need a reroll, but in the meantime, the tip in #21 works for Drupal 8 as well.
Comment #77
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedComment #85
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #86
_utsavsharma CreditAttribution: _utsavsharma at OpenSense Labs commentedTried to fix CCF for 10.1.x in #77.