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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

weekbeforenext’s picture

Status: Active » Needs review
FileSize
5.74 KB

Attached is a patch that allows multiple User IDs as Contextual Filter.

weekbeforenext’s picture

Status: Needs review » Needs work

I see some changes that need to be made to that patch. I'm going to work on it more.

elBradford’s picture

There'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.

couturier’s picture

Marked http://drupal.org/node/1534720 as a duplicate.

weekbeforenext’s picture

Status: Needs work » Needs review
FileSize
6.26 KB

I 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.

Stefan Vaduva’s picture

Was this solved in the end (changing = to IN)?

adrian.andrzejewski’s picture

For 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.

weekbeforenext’s picture

I 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.

weekbeforenext’s picture

I 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

weekbeforenext’s picture

Attached is a patch that will not trigger trailing whitespace errors when applied.

Thanks,
April

weekbeforenext’s picture

Category: Feature request » Bug report
Issue summary: View changes
NaX’s picture

Status: Needs review » Needs work

Thanks 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:

  • Use the default break_phrase option rather than creating a new one as the default one is required. $this->options['break_phrase']
  • Use the built-in views_break_phrase() function for splitting the argument.

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.

johnkareoke’s picture

Just 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.

jts86’s picture

#10 worked for me, marking both the new multiple values checkbox and the conventional one at the More section.

zalak.addweb’s picture

Issue tags: +views
riddhi.addweb’s picture

fishfree’s picture

@weekbeforenext Your patch cannot apply to the newest Views module, now. Would be please paste your hook_views_query_alter() code?

DamienMcKenna’s picture

Issue tags: -views +Needs reroll
Andrew Answer’s picture