As pointed out in views_user.inc when describing views_handler_filter_username():

/*
 * Create a list of usernames.
 * I worry this will really, really suck for large sites.
 * But then, why would large sites create a filter for one particular user?
 * Better to go with roles.
 */

We have a requirement to allow the user to filter by Author Name within a specific role. This patch provides similar functionality to the "Taxonomy: Terms for vocabulary name" filters in views_taxonomy.inc, only for Users in Roles as opposed to Terms in Vocabularies.

Would this be better as a contribution? Given the Taxonomy precedent above, it feels like this should be distributed with Views.

CommentFileSizeAuthor
views_user.inc.patch2.25 KBmarcp
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Status: Needs review » Needs work

I agree that this is useful and worthy of core. In a publishing context, one might want an exposed filter for all editors.

I tried the patch but no additional filters showed up even though I have extra roles and did clear cache.

Anyway, this will make the filter list grow substantially for sites with many roles. Couldn't we define one filter with an Option to specify a role when setting up the filter. See the Option column in the fields section of View form.

merlinofchaos’s picture

The value list array is populated without knowledge of the option, I believe. I'm not sure it's plausible for that to work.

marcp’s picture

Hmmm, did the patch apply for you, Moshe? You should see entries in the "Add filter" combo box that are called "Node: Authors in role ____" for each role...

I agree that it clutters up the filter list the same way that the "Taxonomy: Terms for ______" entries do. It'd be great if we could do this with a single filter and utilize the Option ... if it's possible.

marcp’s picture

Status: Needs work » Needs review

Just wondering if anyone else has been able to get this patch to work...

merlinofchaos’s picture

Status: Needs review » Fixed

I've applied this, but this gains a similar problem to profile fields, which is that the views cache needs to be cleared before newly added roles will appear. There isn't an easy way to automatically detect this, but I have another solution I think I can implement.

moshe weitzman’s picture

not sure what you have in mind, but we could just add fapi submit handlers on role form and profile form.

Anonymous’s picture

Status: Fixed » Closed (fixed)