diff --git a/src/Builder/FormsStepsListBuilder.php b/src/Builder/FormsStepsListBuilder.php index c932430..5c16ea9 100644 --- a/src/Builder/FormsStepsListBuilder.php +++ b/src/Builder/FormsStepsListBuilder.php @@ -47,18 +47,23 @@ class FormsStepsListBuilder extends ConfigEntityListBuilder { public function getDefaultOperations(EntityInterface $entity): array { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ $operations = parent::getDefaultOperations($entity); - $first_step = $entity->getFirstStep(); + + try { + $first_step = $entity->getFirstStep(); + // View action is only displayed when the forms steps has at least one step. + if ($first_step) { + $uri = $first_step->url(); - // View action is only displayed when the forms steps has at least one step. - if ($first_step) { - $uri = $first_step->url(); - - $operations['display'] = [ - 'title' => $this->t('View'), - 'weight' => 20, - 'url' => Url::fromUri("internal:$uri"), - ]; + $operations['display'] = [ + 'title' => $this->t('View'), + 'weight' => 20, + 'url' => Url::fromUri("internal:$uri"), + ]; + } + } catch (\InvalidArgumentException $e) { + // No steps available, so no View operation will be shown. } + return $operations; } diff --git a/src/Entity/FormsSteps.php b/src/Entity/FormsSteps.php index 4ca1eb2..4b62d96 100644 --- a/src/Entity/FormsSteps.php +++ b/src/Entity/FormsSteps.php @@ -406,7 +406,11 @@ class FormsSteps extends ConfigEntityBase implements FormsStepsInterface { if ($steps === NULL) { $steps = $this->getSteps(); } - return reset($steps); + $first_step = reset($steps); + if ($first_step === FALSE) { + throw new \InvalidArgumentException('No steps available to get first step.'); + } + return $first_step; } @@ -417,7 +421,11 @@ class FormsSteps extends ConfigEntityBase implements FormsStepsInterface { if ($steps === NULL) { $steps = $this->getSteps(); } - return end($steps); + $last_step = end($steps); + if ($last_step === FALSE) { + throw new \InvalidArgumentException('No steps available to get last step.'); + } + return $last_step; }