So you need to add 2 field into your view User uid
(exclude from display) and Custom text
, next go to your template.php
and do next
//implement hook_preprocess_views_view_fields
function YOURTHEME_preprocess_views_view_fields(&$vars) {
$view = $vars['view'];
$fields = $vars['fields'];
if ($view->name == 'usr1') { // change on your view name
$results = $view->result;
$roles = array();
foreach ($results as $row) {
$user = user_load($row->uid);
$roles = implode(', ',$user->roles ); //get all user roles
//check if user name from field equal to current user in array
if ($fields['name']->raw === $row->users_name) {
$fields['nothing']->content = $roles;//put that roles to custom text field
}
}
}
}
THIS CODE NEED IMPROVEMENTS, cuz it iteracts on every field of your view, so you can work on this :D.
If enabled, some fields may become unavailable.
– Petro Popelyshko Dec 14 '12 at 15:02