function Permissions::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/ Permissions.php, line 40 - Definition of Views\user\Plugin\views\field\Permissions.
Class
- Permissions
- Field handler to provide a list of permissions.
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) {
// Get a list of all the modules implementing a hook_permission() and sort by
// display name.
$module_info = system_get_info('module');
$modules = array();
foreach (module_implements('permission') as $module) {
$modules[$module] = $module_info[$module]['name'];
}
asort($modules);
$permissions = module_invoke_all('permission');
$query = db_select('role_permission', 'rp');
$query
->join('users_roles', 'u', 'u.rid = rp.rid');
$query
->fields('u', array(
'uid',
'rid',
));
$query
->addField('rp', 'permission');
$query
->condition('u.uid', $uids);
$query
->condition('rp.module', array_keys($modules));
$query
->orderBy('rp.permission');
$result = $query
->execute();
foreach ($result as $perm) {
$this->items[$perm->uid][$perm->permission]['permission'] = $permissions[$perm->permission]['title'];
}
}
}