You are here

public function RoleExpireConfigurationForm::submitForm in Role Expire 8

Same name and namespace in other branches
  1. 2.x src/Form/RoleExpireConfigurationForm.php \Drupal\role_expire\Form\RoleExpireConfigurationForm::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

src/Form/RoleExpireConfigurationForm.php, line 125

Class

RoleExpireConfigurationForm
Configure order for this site.

Namespace

Drupal\role_expire\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $excluded_roles = [
    'anonymous',
    'authenticated',
  ];
  $data = [];
  $dataDisabled = [];
  $parsed_roles = [];
  $roles = user_roles();
  foreach ($roles as $role) {
    $parsed_roles[$role
      ->id()] = $role
      ->label();
  }
  foreach ($parsed_roles as $rid => $role_name) {
    if (!in_array($rid, $excluded_roles)) {
      $data[$rid] = $values[$rid];
      $dataDisabled[$rid] = $values['disable_' . $rid];
    }
  }
  $this
    ->config('role_expire.config')
    ->set('role_expire_default_roles', json_encode($data))
    ->save();
  $this
    ->config('role_expire.config')
    ->set('role_expire_disabled_roles', json_encode($dataDisabled))
    ->save();
  parent::submitForm($form, $form_state);
}