You are here

public function FormsSteps::getPreviousStep in Forms Steps 8

Returns the previous step to $step.

Parameters

\Drupal\forms_steps\Step $step: The current Step.

Return value

\Drupal\forms_steps\Step|null Returns the previous Step or first step if no previous step found.

Overrides FormsStepsInterface::getPreviousStep

1 call to FormsSteps::getPreviousStep()
FormsSteps::getPreviousStepRoute in src/Entity/FormsSteps.php
Returns the previous step route.

File

src/Entity/FormsSteps.php, line 280

Class

FormsSteps
FormsSteps configuration entity to persistently store configuration.

Namespace

Drupal\forms_steps\Entity

Code

public function getPreviousStep(Step $step) {
  $previousStep = NULL;

  // Reverse the order of the array.
  $stepsReversed = array_reverse($this
    ->getSteps());
  $stepsIterator = new \ArrayIterator($stepsReversed);
  while ($stepsIterator
    ->valid()) {
    if (strcmp($stepsIterator
      ->current()
      ->id(), $step
      ->id()) == 0) {
      $stepsIterator
        ->next();
      $previousStep = $stepsIterator
        ->current();
      break;
    }
    else {
      $stepsIterator
        ->next();
    }
  }
  return $previousStep;
}