/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($roles = array_filter($form_state->getValue('roles'))) {
         foreach ($roles as $key => $role) {
             $roles[$key] = $this->roleStorage->load($role)->label();
         }
         // Authenticated role includes all users so we can ignore all other roles.
         $properties = [];
         if (!array_key_exists(AccountInterface::AUTHENTICATED_ROLE, $roles)) {
             $properties['roles'] = array_keys($roles);
         }
         $users = $this->userStorage->loadByProperties($properties);
         $exclude_myself = $form_state->getValue('exclude_myself') == '1';
         $account = \Drupal::currentUser();
         /** @var \Drupal\user\UserInterface $user */
         foreach ($users as $user) {
             if ($exclude_myself && $user->id() == $account->id()) {
                 continue;
             }
             if ($user->hasRole(AccountInterface::ANONYMOUS_ROLE)) {
                 continue;
             }
             $user->set('field_password_expiration', '1');
             $user->save();
         }
         drupal_set_message($this->formatPlural(count($roles), 'Reset the %roles role.', 'Reset the %roles roles.', ['%roles' => implode(', ', array_values($roles))]));
     } else {
         drupal_set_message($this->t('No roles selected.'), 'warning');
     }
     $form_state->setRedirectUrl(new Url('entity.password_policy.collection'));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = array();
     foreach ($this->value as $role_id) {
         $role = $this->roleStorage->load($role_id);
         $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
     }
     return $dependencies;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     foreach (array_keys($this->options['role']) as $rid) {
         if ($role = $this->roleStorage->load($rid)) {
             $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
         }
     }
     return $dependencies;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $roles = $form_state->getValue('roles');
     $role_names = [];
     foreach ($roles as $role) {
         if ($role_obj = $this->role_storage->load($role)) {
             $role_names[] = $role_obj->label();
         } else {
             $role_names[] = $role;
         }
         $users = $this->user_storage->loadByProperties(['roles' => $role]);
         foreach ($users as $user) {
             if ($form_state->getValue('exclude_myself') == '1' and $user->id() == \Drupal::currentUser()->id()) {
                 continue;
             }
             $user->set('field_password_expiration', '1');
             $user->save();
         }
     }
     drupal_set_message($this->t('Reset the %roles roles.', array('%roles' => implode(', ', $role_names))));
     $form_state->setRedirectUrl(new Url('entity.password_policy.collection'));
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $this->config('user.settings')->set('anonymous', $form_state->getValue('anonymous'))->set('register', $form_state->getValue('user_register'))->set('password_strength', $form_state->getValue('user_password_strength'))->set('verify_mail', $form_state->getValue('user_email_verification'))->set('cancel_method', $form_state->getValue('user_cancel_method'))->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify'))->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify'))->set('notify.status_canceled', $form_state->getValue('user_mail_status_canceled_notify'))->save();
     $this->config('user.mail')->set('cancel_confirm.body', $form_state->getValue('user_mail_cancel_confirm_body'))->set('cancel_confirm.subject', $form_state->getValue('user_mail_cancel_confirm_subject'))->set('password_reset.body', $form_state->getValue('user_mail_password_reset_body'))->set('password_reset.subject', $form_state->getValue('user_mail_password_reset_subject'))->set('register_admin_created.body', $form_state->getValue('user_mail_register_admin_created_body'))->set('register_admin_created.subject', $form_state->getValue('user_mail_register_admin_created_subject'))->set('register_no_approval_required.body', $form_state->getValue('user_mail_register_no_approval_required_body'))->set('register_no_approval_required.subject', $form_state->getValue('user_mail_register_no_approval_required_subject'))->set('register_pending_approval.body', $form_state->getValue('user_mail_register_pending_approval_body'))->set('register_pending_approval.subject', $form_state->getValue('user_mail_register_pending_approval_subject'))->set('status_activated.body', $form_state->getValue('user_mail_status_activated_body'))->set('status_activated.subject', $form_state->getValue('user_mail_status_activated_subject'))->set('status_blocked.body', $form_state->getValue('user_mail_status_blocked_body'))->set('status_blocked.subject', $form_state->getValue('user_mail_status_blocked_subject'))->set('status_canceled.body', $form_state->getValue('user_mail_status_canceled_body'))->set('status_canceled.subject', $form_state->getValue('user_mail_status_canceled_subject'))->save();
     $this->config('system.site')->set('mail_notification', $form_state->getValue('mail_notification_address'))->save();
     // Change the admin role.
     if ($form_state->hasValue('user_admin_role')) {
         $admin_roles = $this->roleStorage->getQuery()->condition('is_admin', TRUE)->execute();
         foreach ($admin_roles as $rid) {
             $this->roleStorage->load($rid)->setIsAdmin(FALSE)->save();
         }
         $new_admin_role = $form_state->getValue('user_admin_role');
         if ($new_admin_role) {
             $this->roleStorage->load($new_admin_role)->setIsAdmin(TRUE)->save();
         }
     }
 }