You are here

public function ReCaptchaV3SettingsForm::submitForm in reCAPTCHA v3 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/ReCaptchaV3SettingsForm.php, line 153

Class

ReCaptchaV3SettingsForm
Configure the google reCAPTCHA v3 api and fallback challenge.

Namespace

Drupal\recaptcha_v3\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $config = $this
    ->config('recaptcha_v3.settings');

  // If site key have been changed,
  // then need to rebuild site libraries and elements.
  if ($config
    ->get('site_key') !== $values['site_key']) {
    $this->libraryDiscovery
      ->clearCachedDefinitions();
    $this->elementInfoManager
      ->clearCachedDefinitions();
  }
  $this
    ->config('recaptcha_v3.settings')
    ->set('site_key', $values['site_key'])
    ->set('secret_key', $values['secret_key'])
    ->set('verify_hostname', $values['verify_hostname'])
    ->set('default_challenge', $values['default_challenge'])
    ->set('error_message', $values['error_message'])
    ->set('cacheable', $values['cacheable'])
    ->save();
  parent::submitForm($form, $form_state);
}