You are here

public function UserSettingsForm::submitForm in Restrict Login or Role Access by IP Address 8.4

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/UserSettingsForm.php, line 128

Class

UserSettingsForm
Class UserSettingsForm.

Namespace

Drupal\restrict_by_ip\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $config = $this
    ->config('restrict_by_ip.settings');

  // Existing restrictions.
  foreach ($form_state
    ->getValues() as $key => $value) {
    if (strpos($key, 'restrict_by_ip_user_') === FALSE) {
      continue;
    }
    if (strlen($value) > 0) {
      $config
        ->set(str_replace('restrict_by_ip_user_', 'user.', $key), $value);
    }
    else {
      $config
        ->clear(str_replace('restrict_by_ip_user_', 'user.', $key));
    }
  }

  // New restriction.
  if (strlen($form_state
    ->getValue('name')) > 0) {
    $config
      ->set('user.' . $form_state
      ->getValue('name'), $form_state
      ->getValue('restriction'));
  }
  $config
    ->save();
}