Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I wanted the ability to accept multiple User IDs as a contextual filter similar to Node IDs. I have modified the views_plugin_argument_validate_user.inc file to allow this capability. I will attach the patch to the following post.
Comment | File | Size | Author |
---|---|---|---|
#19 | views-contextual_filter_userid_multiple-1798270-19.patch | 8 KB | Andrew Answer |
|
Comments
Comment #1
weekbeforenextAttached is a patch that allows multiple User IDs as Contextual Filter.
Comment #2
weekbeforenextI see some changes that need to be made to that patch. I'm going to work on it more.
Comment #3
elBradford CreditAttribution: elBradford commentedThere's nothing to indicate in the interface that it won't work for user ids, but it doesn't work for me. Eagerly awaiting a patch for this, thanks.
Comment #4
couturier CreditAttribution: couturier commentedMarked http://drupal.org/node/1534720 as a duplicate.
Comment #5
weekbeforenextI reworked the views_plugin_argument_validate_user.inc file and created a new patch. The validation seems to work, but if you enter multiple users, I can't figure out where the view is modified to use the IN operator instead of the = operator. Does anyone know where that needs to be changed? Otherwise, you can use hook_query_alter to modify the query for specific instances. I really want to figure out how to set the correct operator though.
Comment #6
Stefan Vaduva CreditAttribution: Stefan Vaduva commentedWas this solved in the end (changing = to IN)?
Comment #7
adrian.andrzejewski CreditAttribution: adrian.andrzejewski commentedFor people having problem with operator (= instead IN).
For me worked to delete line $this->argument->argument = implode(', ', $account_uids); (after patch this is line 173 in views_plugin_argument_validate_user.inc)
Also make sure "Allow multiple values" checkbox is checked. Hope I help someone.
Comment #8
weekbeforenextI had to solve this by using hook_views_query_alter(). I'm not sure how removing that line fixed the problem, but I will look into it. Maybe the value should just be $account_uids instead of an imploded version. I will take a look at this when I have time. Thanks for your input.
Comment #9
weekbeforenextI finally had some time to investigate this further. adrian.andrzejewski, you were on to something. However, the problem was the space after the column in the implode statement: ', '. When the space was removed, it worked fine.
While investigating the problem with multiple uids/usernames, I noticed that if there was a space in the argument for nids, it caused a problem as well. I added some code to strip out spaces in the argument for both.
Please consider the attached patch.
Thanks,
April
Comment #10
weekbeforenextAttached is a patch that will not trigger trailing whitespace errors when applied.
Thanks,
April
Comment #11
weekbeforenextComment #12
NaX CreditAttribution: NaX commentedThanks for this patch, it helped me a lot. Based on what I learned looking at the code and looking at the default 'views_handler_argument_numeric.inc' I would suggest the following:
$this->options['break_phrase']
To answer your question related to "Where is the query modified." Look in views_handler_argument_numeric.inc query(). To use your option my understanding of how views works you would need to override query in views_handler_argument_user_uid.inc.
Comment #13
johnkareoke CreditAttribution: johnkareoke commentedJust an FYI that might be useful. I was struggling with this same problem after applying the patch in 10 to the dev release of views, 'drush updatedb' and 'drush cc all'. It only starting working after I deleted the contextual filter in question and added it back. Boom! Thanks @weekbeforenext.
Not sure if that is of help to others, but thought I would add it here.
Comment #14
jts86 CreditAttribution: jts86 commented#10 worked for me, marking both the new multiple values checkbox and the conventional one at the More section.
Comment #15
zalak.addweb CreditAttribution: zalak.addweb commentedComment #16
riddhi.addweb CreditAttribution: riddhi.addweb commentedComment #17
fishfree CreditAttribution: fishfree commented@weekbeforenext Your patch cannot apply to the newest Views module, now. Would be please paste your hook_views_query_alter() code?
Comment #18
DamienMcKennaComment #19
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.