Beispiel #1
0
 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]);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $options = [];
     foreach ($this->role_storage->loadMultiple() as $role) {
         $options[$role->id()] = $role->label();
     }
     unset($options[AccountInterface::ANONYMOUS_ROLE]);
     $form['roles'] = ['#type' => 'checkboxes', '#title' => $this->t('Roles'), '#description' => $this->t('Force password reset of selected roles.'), '#options' => $options];
     $form['exclude_myself'] = ['#type' => 'checkbox', '#title' => $this->t('Exclude Myself'), '#description' => $this->t('Exclude your account if you are included in the roles.'), '#default_value' => '1'];
     $form['save'] = ['#type' => 'submit', '#value' => $this->t('Save')];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $cached_values = $form_state->getTemporaryValue('wizard');
     /** @var $policy \Drupal\password_policy\Entity\PasswordPolicy */
     $policy = $cached_values['password_policy'];
     $options = [];
     foreach ($this->storage->loadMultiple() as $role) {
         $options[$role->id()] = $role->label();
     }
     unset($options[AccountInterface::ANONYMOUS_ROLE]);
     $form['roles'] = ['#type' => 'checkboxes', '#title' => $this->t('Apply to Roles'), '#description' => $this->t('Select Roles to which this policy applies.'), '#options' => $options, '#default_value' => $policy->getRoles()];
     return $form;
 }
 /**
  * Gets the roles to display in this form.
  *
  * @return \Drupal\user\RoleInterface[]
  *   An array of role objects.
  */
 protected function getRoles()
 {
     return $this->roleStorage->loadMultiple();
 }