You are here

private function BasicSetup::tfaNextSetupStep in Two-factor Authentication (TFA) 8

Set form rebuild, next step, and message if any plugin steps left.

Parameters

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

string $this_step: The current setup step.

\Drupal\tfa\TfaSetup $step_class: The setup instance of the current step.

bool $skipped_step: Whether the step was skipped.

1 call to BasicSetup::tfaNextSetupStep()
BasicSetup::submitForm in src/Form/BasicSetup.php
Form submission handler.

File

src/Form/BasicSetup.php, line 410

Class

BasicSetup
TFA setup form router.

Namespace

Drupal\tfa\Form

Code

private function tfaNextSetupStep(FormStateInterface &$form_state, $this_step, TfaSetup $step_class, $skipped_step = FALSE) {
  $storage = $form_state
    ->getStorage();

  // Remove this step from steps left.
  $storage['steps_left'] = array_diff($storage['steps_left'], [
    $this_step,
  ]);
  if (!empty($storage['steps_left'])) {

    // Contextual reporting.
    if ($output = $step_class
      ->getSetupMessages()) {
      $output = $skipped_step ? $output['skipped'] : $output['saved'];
    }
    $count = count($storage['steps_left']);
    $output .= ' ' . $this
      ->formatPlural($count, 'One setup step remaining.', '@count TFA setup steps remain.', [
      '@count' => $count,
    ]);
    if ($output) {
      $this
        ->messenger()
        ->addStatus($output);
    }

    // Set next step and mark form for rebuild.
    $next_step = array_shift($storage['steps_left']);
    $storage['step_method'] = $next_step;
    $form_state
      ->setRebuild();
  }
  $form_state
    ->setStorage($storage);
}