You are here

public function HCaptchaAdminSettingsForm::buildForm in hCaptcha 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

src/Form/HCaptchaAdminSettingsForm.php, line 31

Class

HCaptchaAdminSettingsForm
Configure hCaptcha settings for this site.

Namespace

Drupal\hcaptcha\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('hcaptcha.settings');
  $form['general'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('General settings'),
    '#open' => true,
  ];
  $form['general']['hcaptcha_site_key'] = [
    '#default_value' => $config
      ->get('site_key'),
    '#description' => $this
      ->t('The site key given to you when you <a href=":url">register for hCaptcha</a>.', [
      ':url' => 'https://hcaptcha.com/?r=8a46bae6b225',
    ]),
    '#maxlength' => 50,
    '#required' => true,
    '#title' => $this
      ->t('Site key'),
    '#type' => 'textfield',
  ];
  $form['general']['hcaptcha_secret_key'] = [
    '#default_value' => $config
      ->get('secret_key'),
    '#description' => $this
      ->t('The secret key given to you when you <a href=":url">register for hCaptcha</a>.', [
      ':url' => 'https://hcaptcha.com/?r=8a46bae6b225',
    ]),
    '#maxlength' => 50,
    '#required' => true,
    '#title' => $this
      ->t('Secret key'),
    '#type' => 'textfield',
  ];
  $form['general']['hcaptcha_src'] = [
    '#default_value' => $config
      ->get('hcaptcha_src'),
    '#description' => $this
      ->t('Default URL is ":url".', [
      ':url' => 'https://hcaptcha.com/1/api.js',
    ]),
    '#maxlength' => 200,
    '#required' => true,
    '#title' => $this
      ->t('hCaptcha javascript resource URL'),
    '#type' => 'textfield',
  ];

  // Widget configurations.
  $form['widget'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Widget settings'),
    '#open' => true,
  ];
  $form['widget']['hcaptcha_theme'] = [
    '#default_value' => $config
      ->get('widget.theme'),
    '#description' => $this
      ->t('Defines which theme to use for hCaptcha.'),
    '#options' => [
      '' => $this
        ->t('Light (default)'),
      'dark' => $this
        ->t('Dark'),
    ],
    '#title' => $this
      ->t('Theme'),
    '#type' => 'select',
  ];
  $form['widget']['hcaptcha_size'] = [
    '#default_value' => $config
      ->get('widget.size'),
    '#description' => $this
      ->t('The size of CAPTCHA to serve.'),
    '#options' => [
      '' => $this
        ->t('Normal (default)'),
      'compact' => $this
        ->t('Compact'),
    ],
    '#title' => $this
      ->t('Size'),
    '#type' => 'select',
  ];
  $form['widget']['hcaptcha_tabindex'] = [
    '#default_value' => $config
      ->get('widget.tabindex'),
    '#description' => $this
      ->t('Set the <a href=":tabindex">tabindex</a> of the widget and challenge (Default = 0). If other elements in your page use tabindex, it should be set to make user navigation easier.', [
      ':tabindex' => Url::fromUri('https://www.w3.org/TR/html4/interact/forms.html', [
        'fragment' => 'adef-tabindex',
      ])
        ->toString(),
    ]),
    '#maxlength' => 4,
    '#title' => $this
      ->t('Tabindex'),
    '#type' => 'number',
    '#min' => -1,
  ];
  return parent::buildForm($form, $form_state);
}