public function TfaRecoveryCodeSetup::getSetupForm in Two-factor Authentication (TFA) 8
Get the setup form for the validation method.
Parameters
array $form: The configuration form array.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
int $reset: Whether or not the user is resetting the application.
Return value
array Form API array.
Overrides TfaSetupInterface::getSetupForm
File
- src/
Plugin/ TfaSetup/ TfaRecoveryCodeSetup.php, line 91
Class
- TfaRecoveryCodeSetup
- TFA Recovery Code Setup Plugin.
Namespace
Drupal\tfa\Plugin\TfaSetupCode
public function getSetupForm(array $form, FormStateInterface $form_state, $reset = 0) {
$codes = $this
->getCodes();
// If $reset has a value, we're setting up new codes.
if (!empty($reset)) {
$codes = $this
->generateCodes();
// Make the human friendly.
foreach ($codes as $key => $code) {
$codes[$key] = implode(' ', str_split($code, 3));
}
$form['recovery_codes'] = [
'#type' => 'value',
'#value' => $codes,
];
}
$form['recovery_codes_output'] = [
'#title' => $this
->t('Recovery Codes'),
'#theme' => 'item_list',
'#items' => $codes,
];
$form['description'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('Print or copy these codes and store them somewhere safe before continuing.'),
];
if (!empty($reset)) {
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Save codes to account'),
];
}
return $form;
}