function antibot_webform_submission_form_alter in Webform 8.5
Same name and namespace in other branches
- 6.x third_party_settings/webform.antibot.inc \antibot_webform_submission_form_alter()
Implements hook_webform_submission_form_alter().
File
- third_party_settings/
webform.antibot.inc, line 135 - Integrates third party settings on the Antibot module's behalf.
Code
function antibot_webform_submission_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Only add an Antibot when a webform is initially load.
// After a webform is submitted, via a multi-step webform and/or saving a draft,
// we can skip adding an Antibot.
if ($form_state
->isSubmitted()) {
return;
}
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $form_state
->getFormObject()
->getEntity();
$webform = $webform_submission
->getWebform();
$antibot = $third_party_settings_manager
->getThirdPartySetting('antibot', 'antibot') ?: $webform
->getThirdPartySetting('antibot', 'antibot');
if ($antibot) {
if (function_exists('antibot_protect_form')) {
// Applies to antibot-8.x-1.2+
// Set #form_id which is needed by antibot_protect_form().
$form['#form_id'] = $form_id;
antibot_protect_form($form);
}
else {
// Applies to antibot-8.x-1.1 and below.
// @todo Remove backward compatibility for antibot-8.x-1.1.
$form['#pre_render'][] = 'antibot_form_pre_render';
}
}
}