You are here

public function GALoginTotpValidation::buildConfigurationForm in Google Authenticator login 8

The configuration form for this validation plugin.

Parameters

\Drupal\Core\Config\Config $config: Config object for tfa settings.

array $state: Form state array determines if this form should be shown.

Return value

array Form array specific for this validation plugin.

File

src/Plugin/TfaValidation/GALoginTotpValidation.php, line 172

Class

GALoginTotpValidation
TOTP validation class for performing TOTP validation.

Namespace

Drupal\ga_login\Plugin\TfaValidation

Code

public function buildConfigurationForm(Config $config, array $state = []) {
  $settings_form['time_skew'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Number of Accepted Codes'),
    '#default_value' => $this->timeSkew,
    '#description' => $this
      ->t('Number of past codes to consider valid. Codes are generated every 30 seconds, so setting this value to 10 would allow each code to work for five minutes.'),
    '#size' => 2,
    '#states' => $state,
    '#required' => TRUE,
  ];
  $settings_form['site_name_prefix'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use site name as OTP QR code name prefix.'),
    '#default_value' => $this->siteNamePrefix,
    '#description' => $this
      ->t('If checked, the site name will be used instead of a static string. This can be useful for multi-site installations.'),
    '#states' => $state,
  ];

  // Hide custom name prefix when site name prefix is selected.
  $state['visible'] += [
    ':input[name="validation_plugin_settings[ga_login_totp][site_name_prefix]"]' => [
      'checked' => FALSE,
    ],
  ];
  $settings_form['name_prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('OTP QR Code Prefix'),
    '#default_value' => $this->namePrefix ?: 'tfa',
    '#description' => $this
      ->t('Prefix for OTP QR code names. Suffix is account username.'),
    '#size' => 15,
    '#states' => $state,
  ];
  $settings_form['issuer'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Issuer'),
    '#default_value' => $this->issuer,
    '#description' => $this
      ->t('The provider or service this account is associated with.'),
    '#size' => 15,
    '#required' => TRUE,
  ];
  return $settings_form;
}