You are here

function captcha_webform_admin_third_party_settings_form_alter in Webform 8.5

Same name and namespace in other branches
  1. 6.x third_party_settings/webform.captcha.inc \captcha_webform_admin_third_party_settings_form_alter()

Implements hook_webform_admin_third_party_settings_form_alter().

File

third_party_settings/webform.captcha.inc, line 15
Integrates third party settings on the CAPTCHA module's behalf.

Code

function captcha_webform_admin_third_party_settings_form_alter(&$form, FormStateInterface $form_state) {

  /** @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');
  $t_args = [
    ':href' => Url::fromRoute('captcha_settings')
      ->toString(),
    '@from' => t('Place a CAPTCHA here for untrusted users.'),
    '@to' => t('Add CAPTCHA element to this webform for untrusted users.'),
  ];
  $form['third_party_settings']['captcha'] = [
    '#type' => 'details',
    '#title' => t('CAPTCHA'),
    '#description' => t('Provides the <a href=":href">CAPTCHA</a> for adding challenges to forms.', [
      ':href' => 'https://en.wikipedia.org/wiki/CAPTCHA',
    ]),
    '#open' => TRUE,
  ];
  $form['third_party_settings']['captcha']['replace_administration_mode'] = [
    '#type' => 'checkbox',
    '#title' => t('Replace <em>Add CAPTCHA administration links to forms</em> with CAPTCHA webform element'),
    '#description' => t('If checked and <a href=":href">Add CAPTCHA administration links to forms</a> is enabled, the CAPTCHA fieldset added to every form will create a new CAPTCHA webform element instead of tracking each webform\'s id.', $t_args) . '<br/><br/>' . t('It changes the "@from" link label and behavior to "@to"', $t_args),
    '#default_value' => $replace_administration_mode,
    '#return_value' => TRUE,
  ];
}