You are here

public function FormsSteps::getSteps in Forms Steps 8

Gets step objects for the provided step IDs.

Parameters

string[] $step_ids: A list of step IDs to get. If NULL then all steps will be returned.

Return value

\Drupal\forms_steps\StepInterface[] An array of forms_steps steps.

Throws

\InvalidArgumentException Thrown if $step_ids contains a step ID that does not exist.

Overrides FormsStepsInterface::getSteps

4 calls to FormsSteps::getSteps()
FormsSteps::getFirstStep in src/Entity/FormsSteps.php
Retrieve the first step defined on a forms steps entity.
FormsSteps::getLastStep in src/Entity/FormsSteps.php
Retrieve the last step defined on a forms steps entity.
FormsSteps::getNextStep in src/Entity/FormsSteps.php
Returns the next step to $step.
FormsSteps::getPreviousStep in src/Entity/FormsSteps.php
Returns the previous step to $step.

File

src/Entity/FormsSteps.php, line 350

Class

FormsSteps
FormsSteps configuration entity to persistently store configuration.

Namespace

Drupal\forms_steps\Entity

Code

public function getSteps(array $step_ids = NULL) {
  if ($step_ids === NULL) {
    $step_ids = array_keys($this->steps);
  }

  /** @var \Drupal\forms_steps\StepInterface[] $steps */
  $steps = array_combine($step_ids, array_map([
    $this,
    'getStep',
  ], $step_ids));
  if (count($steps) > 1) {

    // Sort Steps by weight and then label.
    $weights = $labels = [];
    foreach ($steps as $id => $step) {
      $weights[$id] = $step
        ->weight();
      $labels[$id] = $step
        ->label();
    }
    array_multisort($weights, SORT_NUMERIC, SORT_ASC, $labels, SORT_NATURAL, SORT_ASC);
    $steps = array_replace($weights, $steps);
  }
  return $steps;
}