function captcha_webform_submission_form_alter in Webform 8.5
Same name and namespace in other branches
- 6.x third_party_settings/webform.captcha.inc \captcha_webform_submission_form_alter()
Implements hook_webform_submission_form_alter().
File
- third_party_settings/
webform.captcha.inc, line 45 - Integrates third party settings on the CAPTCHA module's behalf.
Code
function captcha_webform_submission_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Make sure CAPTCHA admin mode is enabled and available to the current user.
$config = \Drupal::config('captcha.settings');
if (!$config
->get('administration_mode') || !\Drupal::currentUser()
->hasPermission('administer CAPTCHA settings')) {
return;
}
// Make sure the CAPTCHA webform element is enabled.
/** @var \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager */
$element_manager = \Drupal::service('plugin.manager.webform.element');
if ($element_manager
->isExcluded('captcha')) {
return;
}
// Make sure replace administrative mode is enabled.
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
$replace_administration_mode = $third_party_settings_manager
->getThirdPartySetting('captcha', 'replace_administration_mode');
if (!$replace_administration_mode) {
return;
}
// If the webform already has a CAPTCHA point is already configured, do not
// do anything.
/* @var \Drupal\captcha\CaptchaPointInterface $captcha_point */
$captcha_point = \Drupal::entityTypeManager()
->getStorage('captcha_point')
->load($form_id);
if ($captcha_point) {
return;
}
$form['#after_build'][] = '_captcha_webform_submission_form_after_build';
}