You are here

public function RoleAccessControlAdminForm::submitForm in Role Access Control 8

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 FormInterface::submitForm

File

src/Form/RoleAccessControlAdminForm.php, line 114

Class

RoleAccessControlAdminForm
Contribute form.

Namespace

Drupal\rac\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this
    ->configFactory()
    ->getEditable("rac.settings")
    ->set('update_unpublished', $form_state
    ->getValue('update_unpublished'))
    ->save();
  $values = $form_state
    ->getValues();
  $roles = user_roles();
  foreach ($roles as $rid => $role) {
    if ($role
      ->isAdmin()) {
      continue;
    }
    foreach ($values[$rid] as $srid => $role_grant) {
      $permission = "RAC_update_" . $srid;
      if ($role_grant && !$role
        ->hasPermission($permission)) {
        $role
          ->grantPermission($permission);
        $role
          ->save();
      }
      elseif (!$role_grant && $role
        ->hasPermission($permission)) {
        $role
          ->revokePermission($permission);
        $role
          ->save();
      }
    }
  }
  drupal_set_message($this
    ->t("Role Access Permissions Saved"));
}