public function SimpleRecaptchaWebformHandler::alterForm in Simple Google reCAPTCHA 8
Alter webform submission form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
Overrides WebformHandlerBase::alterForm
File
- modules/
simple_recaptcha_webform/ src/ Plugin/ WebformHandler/ SimpleRecaptchaWebformHandler.php, line 141
Class
- SimpleRecaptchaWebformHandler
- Webform submission handler plugin.
Namespace
Drupal\simple_recaptcha_webform\Plugin\WebformHandlerCode
public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
// Skip for users with bypass permission.
if ($this->currentUser
->hasPermission('bypass simple_recaptcha')) {
return;
}
$configuration = $this
->getConfiguration();
$info = $form_state
->getBuildInfo();
switch ($configuration['settings']['recaptcha_type']) {
case 'v3':
$settings = $configuration['settings'];
$settings['recaptcha_action'] = $this
->getWebform()
->id();
$this->reCaptchaFormManager
->addReCaptchaInvisible($form, $info['form_id'], $settings);
break;
case 'v2':
default:
$this->reCaptchaFormManager
->addReCaptchaCheckbox($form, $info['form_id']);
break;
}
return $form;
}