You are here

public function RandomCaptchaTypeSettingsForm::buildForm in CAPTCHA Pack 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

random_captcha_type/src/Form/RandomCaptchaTypeSettingsForm.php, line 40

Class

RandomCaptchaTypeSettingsForm
Random CAPTCHA type settings form.

Namespace

Drupal\random_captcha_type\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $enabled_types = _random_captcha_type_get_enabled_types();
  if (count($enabled_types) < 2) {
    drupal_set_message($this
      ->t('You need at least two CAPTCHA types (other than %random_captcha_type).', [
      '%random_captcha_type' => 'Random CAPTCHA type',
    ]), 'error');
  }
  $form = [];
  $captcha_types = _random_captcha_type_get_all_types();
  $form['random_captcha_type_enabled_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Randomly switch between'),
    '#options' => $captcha_types,
    '#default_value' => $enabled_types,
  ];
  return parent::buildForm($form, $form_state);
}