function Permissions::preRender

Same name in other branches
  1. 9 core/modules/user/src/Plugin/views/field/Permissions.php \Drupal\user\Plugin\views\field\Permissions::preRender()
  2. 8.9.x core/modules/user/src/Plugin/views/field/Permissions.php \Drupal\user\Plugin\views\field\Permissions::preRender()
  3. 11.x core/modules/user/src/Plugin/views/field/Permissions.php \Drupal\user\Plugin\views\field\Permissions::preRender()

Overrides FieldPluginBase::preRender

File

core/modules/user/src/Plugin/views/field/Permissions.php, line 83

Class

Permissions
Field handler to provide a list of permissions.

Namespace

Drupal\user\Plugin\views\field

Code

public function preRender(&$values) {
    $this->items = [];
    $permission_names = \Drupal::service('user.permissions')->getPermissions();
    $rids = [];
    foreach ($values as $result) {
        $user = $this->getEntity($result);
        if ($user) {
            $user_rids = $user->getRoles();
            $uid = $this->getValue($result);
            foreach ($user_rids as $rid) {
                $rids[$rid][] = $uid;
            }
        }
    }
    if ($rids) {
        $roles = $this->roleStorage
            ->loadMultiple(array_keys($rids));
        foreach ($rids as $rid => $role_uids) {
            foreach ($roles[$rid]->getPermissions() as $permission) {
                foreach ($role_uids as $uid) {
                    $this->items[$uid][$permission]['permission'] = $permission_names[$permission]['title'];
                }
            }
        }
        foreach ($this->items as &$permission) {
            ksort($permission);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.