function Roles::pre_render in Views (for Drupal 7) 8.3
Run before any fields are rendered.
This gives the handlers some time to set up before any handler has been rendered.
Parameters
$values: An array of all objects returned from the query.
Overrides FieldPluginBase::pre_render
File
- lib/
Views/ user/ Plugin/ views/ field/ Roles.php, line 40 - Definition of Views\user\Plugin\views\field\Roles.
Class
- Roles
- Field handler to provide a list of roles.
Namespace
Views\user\Plugin\views\fieldCode
function pre_render(&$values) {
$uids = array();
$this->items = array();
foreach ($values as $result) {
$uids[] = $this
->get_value($result);
}
if ($uids) {
$query = db_select('role', 'r');
$query
->join('users_roles', 'u', 'u.rid = r.rid');
$query
->addField('r', 'name');
$query
->fields('u', array(
'uid',
'rid',
));
$query
->condition('u.uid', $uids);
$query
->orderBy('r.name');
$result = $query
->execute();
foreach ($result as $role) {
$this->items[$role->uid][$role->rid]['role'] = check_plain($role->name);
$this->items[$role->uid][$role->rid]['rid'] = $role->rid;
}
}
}