function _webform_antibot_form in Webform 8.5
Same name and namespace in other branches
- 6.x third_party_settings/webform.antibot.inc \_webform_antibot_form()
Alter webform third party settings webforms to include Antibot configuration.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
bool $antibot: TRUE if antibot protection is enabled.
int $antibot_state: Flag that determines if antibot protection is enabled, disabled, or can be set.
string|\Drupal\Core\StringTranslation\TranslatableMarkup $label: The label to displayed within the checkbox titles.
2 calls to _webform_antibot_form()
- antibot_webform_admin_third_party_settings_form_alter in third_party_settings/
webform.antibot.inc - Implements hook_webform_admin_third_party_settings_form_alter().
- antibot_webform_third_party_settings_form_alter in third_party_settings/
webform.antibot.inc - Implements hook_webform_third_party_settings_form_alter().
File
- third_party_settings/
webform.antibot.inc, line 41 - Integrates third party settings on the Antibot module's behalf.
Code
function _webform_antibot_form(array &$form, FormStateInterface $form_state, $antibot, $antibot_state, $label) {
$t_args = [
'%label' => $label,
':href_antibot' => Url::fromRoute('antibot.settings')
->toString(),
':href_webform' => Url::fromRoute('webform.config')
->toString(),
];
// Antibot.
$form['third_party_settings']['antibot'] = [
'#type' => 'details',
'#title' => t('Antibot'),
'#open' => TRUE,
'#description' => t('Prevent SPAM webform submissions from being submitted without JavaScript enabled using the <a href=":href_antibot">antibot</a> method.', $t_args),
];
$form['third_party_settings']['antibot']['antibot'] = [
'#type' => 'checkbox',
'#title' => t('Protect %label with Antibot', $t_args),
'#default_value' => $antibot,
'#return_value' => TRUE,
];
$antibot_state = (int) $antibot_state;
if ($antibot_state !== WEBFORM_ANTIBOT_NEUTRAL) {
$form['third_party_settings']['antibot']['antibot']['#attributes']['disabled'] = 'disabled';
$form_state
->set('antibot_disabled', TRUE);
if ($antibot_state === WEBFORM_ANTIBOT_ENABLED_WEBFORM) {
$form['third_party_settings']['antibot']['antibot']['#default_value'] = 1;
$form['third_party_settings']['antibot']['antibot']['#description'] = t('<a href=":href_webform">Antibot protection</a> is enabled for all webforms.', $t_args);
}
}
$form['#validate'][] = '_webform_antibot_form_validate';
}