1

I have a standard Drupal installation with Views and Administration Views modules installed.

By default, the Users view has a column Roles with ALL the users roles.

How to include a custom column (to replace the default Roles column) to show if the user has or hasn't a specific role (like a yes/no column)?

2
  • Can you be more clear as there is already a column Roles, and you can also filter by an exposed filter on Role Commented Aug 12, 2014 at 19:05
  • Hi Reynolds, I edited the question to be more clear. I don't need (now) to filter rows, only show a yes/no for a specific role.
    – Eduardo
    Commented Aug 12, 2014 at 19:55

1 Answer 1

1

I don't see an out of the box method. Maybe someone else will have a better answer. But what I did for a quick solutions is to add the Views PHP module, then add a PHP field with the following output code:

<?php 

  $account = user_load($data->uid);

  $roles = array('YOURROLE', 'ANOTHER ROLE');

  if (count(array_intersect($roles, $account->roles))) {
    print 'Yes';
  }
  else {
    print  'No';
  }

?>

It will print yes if any user has either of the two roles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.