You are here

function _text_captcha_word_pool_form_items in CAPTCHA Pack 8

Same name and namespace in other branches
  1. 5 text_captcha/text_captcha.inc \_text_captcha_word_pool_form_items()
  2. 6 text_captcha/text_captcha.inc \_text_captcha_word_pool_form_items()
  3. 7 text_captcha/text_captcha.inc \_text_captcha_word_pool_form_items()

Helper function for setting word pool form items locale dependent.

3 calls to _text_captcha_word_pool_form_items()
LostCharacterCaptchaSettingsForm::buildForm in text_captcha/modules/lost_character_captcha/src/Form/LostCharacterCaptchaSettingsForm.php
Form constructor.
PhraseCaptchaSettingsForm::buildForm in text_captcha/modules/phrase_captcha/src/Form/PhraseCaptchaSettingsForm.php
Form constructor.
WordListCaptchaSettingsForm::buildForm in text_captcha/modules/word_list_captcha/src/Form/WordListCaptchaSettingsForm.php
Form constructor.

File

text_captcha/text_captcha.module, line 97
Contains general functionality for the module.

Code

function _text_captcha_word_pool_form_items(&$form, $name_base, $title, $description, $default_value, $rows = 3) {
  if (Drupal::moduleHandler()
    ->moduleExists('locale')) {

    // Locale available.
    $langs = \Drupal::languageManager()
      ->getLanguages();
    $form[$name_base] = [
      '#type' => 'fieldset',
      '#title' => t($title),
      '#description' => t($description),
      '#collapsible' => TRUE,
    ];
    foreach ($langs as $lang_code => $lang_name) {
      $form[$name_base]["{$name_base}_{$lang_code}"] = [
        '#type' => 'textarea',
        '#title' => t('For language %lang_name (code %lang_code)', [
          '%lang_name' => $lang_name,
          '%lang_code' => $lang_code,
        ]),
        '#default_value' => _text_captcha_word_pool_get_content($name_base, $lang_code, $default_value),
        '#rows' => $rows,
      ];
    }
  }
  else {

    // No locale available.
    $form[$name_base] = [
      '#type' => 'textarea',
      '#title' => t($title),
      '#description' => t($description),
      '#default_value' => _text_captcha_word_pool_get_content($name_base, NULL, $default_value),
      '#rows' => $rows,
    ];
  }
}