You are here

public function UserExpireSettingsForm::submitForm in User Expire 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 ConfigFormBase::submitForm

File

src/Form/UserExpireSettingsForm.php, line 143

Class

UserExpireSettingsForm
User expire admin settings form.

Namespace

Drupal\user_expire\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state
    ->cleanValues();
  $config = $this
    ->config('user_expire.settings');
  if (!empty($form_state
    ->getValue('frequency'))) {
    $config
      ->set('frequency', (int) $form_state
      ->getValue('frequency'));
  }
  if (!empty($form_state
    ->getValue('offset'))) {
    $config
      ->set('offset', (int) $form_state
      ->getValue('offset'));
  }

  // Insert the rows that were inserted.
  $rules = $config
    ->get('user_expire_roles') ?: [];
  foreach ($form_state
    ->getValue('current_roles') as $rid => $role) {

    // Only save non-zero values.
    if (!empty($form_state
      ->getValue('user_expire_' . $rid))) {
      $rules[$rid] = (int) $form_state
        ->getValue('user_expire_' . $rid);
    }
  }
  $config
    ->set('user_expire_roles', $rules);
  $config
    ->save();
}