function RoleSettingsForm::submitForm

Same name in other branches
  1. 10 core/modules/user/src/Form/RoleSettingsForm.php \Drupal\user\Form\RoleSettingsForm::submitForm()
  2. 11.x core/modules/user/src/Form/RoleSettingsForm.php \Drupal\user\Form\RoleSettingsForm::submitForm()

Overrides FormInterface::submitForm

File

core/modules/user/src/Form/RoleSettingsForm.php, line 91

Class

RoleSettingsForm
Configure administrator role settings for this site.

Namespace

Drupal\user\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    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();
        }
    }
}

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