You are here

protected function SimpleReCaptchaFormManager::addSubmitHandler in Simple Google reCAPTCHA 8

Add our custom submit handler to the form.

Parameters

array $form: The form.

2 calls to SimpleReCaptchaFormManager::addSubmitHandler()
SimpleReCaptchaFormManager::addReCaptchaCheckbox in src/SimpleReCaptchaFormManager.php
Add reCaptcha v2 container and libraries to the form.
SimpleReCaptchaFormManager::addReCaptchaInvisible in src/SimpleReCaptchaFormManager.php
Add reCaptcha v3 container and libraries to the form.

File

src/SimpleReCaptchaFormManager.php, line 325

Class

SimpleReCaptchaFormManager
Provides helper service used to attach reCaptcha to forms.

Namespace

Drupal\simple_recaptcha

Code

protected function addSubmitHandler(&$form) {

  // We need to register a custom submit handler to clear out session data
  // we no longer need, but we cannot just add it to the base form array
  // #submit property, since action-specific handlers override this. First we
  // check if any of those exist and add it to them instead.
  $specificActionHandlersUsed = FALSE;
  if (isset($form['actions'])) {
    foreach (array_keys($form['actions']) as $action) {
      if (isset($form['actions'][$action]['#submit'])) {
        $form['actions'][$action]['#submit'][] = [
          $this,
          'clearSessionData',
        ];
        $specificActionHandlersUsed = TRUE;
      }
    }
  }
  if (!$specificActionHandlersUsed) {
    $form['#submit'][] = [
      $this,
      'clearSessionData',
    ];
  }
}