You are here

public function AccountSettingsForm::submitForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/AccountSettingsForm.php \Drupal\user\AccountSettingsForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

core/modules/user/src/AccountSettingsForm.php, line 430
Contains \Drupal\user\AccountSettingsForm.

Class

AccountSettingsForm
Configure user settings for this site.

Namespace

Drupal\user

Code

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();
    }
  }
}