You are here

public function UserMfaSetup::buildForm in Google Authenticator / 2 Factor Authentication - 2FA 8.2

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 FormInterface::buildForm

File

src/Form/UserMfaSetup.php, line 52

Class

UserMfaSetup

Namespace

Drupal\miniorange_2fa\form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $variables_and_values = array(
    'mo_auth_enable_two_factor',
  );
  $mo_db_values = MoAuthUtilities::miniOrange_set_get_configurations($variables_and_values, 'GET');
  \Drupal::service('page_cache_kill_switch')
    ->trigger();
  $account = $this
    ->currentUser();

  // We can't let you see the settings if you are not admin and trying to edit 2FA for some other user
  if (!$mo_db_values['mo_auth_enable_two_factor'] || !MoAuthUtilities::isUserCanSee2FASettings() || !$this->isAdmin && $account
    ->id() !== $this->entityId) {
    return $form;
  }
  $form['mo_mfa_enable'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable MFA for your account'),
    '#default_value' => empty($this->savedFields) || !array_key_exists("enabled", (array) $this->savedFields[0]) ? 0 : $this->savedFields[0]->enabled,
    '#description' => $this
      ->t('Note: You will not be prompted for 2FA if you disable this'),
  );
  $form['mo_mfa_form_save'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  );
  return $form;
}