You are here

public function Permissions::preRender in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Plugin/views/field/Permissions.php \Drupal\user\Plugin\views\field\Permissions::preRender()

Runs before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.

Overrides FieldPluginBase::preRender

File

core/modules/user/src/Plugin/views/field/Permissions.php, line 82
Contains \Drupal\user\Plugin\views\field\Permissions.

Class

Permissions
Field handler to provide a list of permissions.

Namespace

Drupal\user\Plugin\views\field

Code

public function preRender(&$values) {
  $uids = array();
  $this->items = array();
  $permission_names = \Drupal::service('user.permissions')
    ->getPermissions();
  $rids = array();
  foreach ($values as $result) {
    $user_rids = $this
      ->getEntity($result)
      ->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 ($uids as $uid) {
      if (isset($this->items[$uid])) {
        ksort($this->items[$uid]);
      }
    }
  }
}