You are here

public function SettingsForm::submitForm in CloudFlare 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/SettingsForm.php, line 355

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\cloudflare\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $api_key = trim($form_state
    ->getValue('apikey'));
  $email = trim($form_state
    ->getValue('email'));

  // Deslash the host URL.
  $bypass_host = trim(rtrim($form_state
    ->getValue('bypass_host'), "/"));
  $client_ip_restore_enabled = $form_state
    ->getValue('client_ip_restore_enabled');
  $config = $this->configFactory
    ->getEditable('cloudflare.settings');
  $config
    ->set('apikey', $api_key)
    ->set('email', $email)
    ->set('valid_credentials', TRUE)
    ->set('bypass_host', $bypass_host)
    ->set('client_ip_restore_enabled', $client_ip_restore_enabled);
  $config
    ->save();
}