Problem/Motivation

TypeError: Drupal\forms_steps\Entity\FormsSteps::getFirstStep(): Return value must be of type Drupal\forms_steps\StepInterface, false returned in Drupal\forms_steps\Entity\FormsSteps->getFirstStep() (line 409 of /app/public/modules/contrib/forms_steps/src/Entity/FormsSteps.php).

Steps to reproduce

- Install / setup clean Drupal without any content type
- go config/workflow/forms_steps
- create workflow
- add step(s) without content type because you dont have any
- check that your form steps are showing on forms step listing
- create a new content type
- now go again config/workflow/forms_steps
- now you see error

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tvalimaa created an issue. See original summary.

markwk’s picture

I hit the same issue. The issue occurs because:

1. FormsStepsListBuilder::getDefaultOperations() calls getFirstStep() to determine if a "View" operation should be shown
2. FormsSteps::getFirstStep() uses reset($steps) which returns FALSE when the array is empty
3. The method signature requires a StepInterface return type, but FALSE is returned instead

The fix involves:
1. Modifying getFirstStep() and getLastStep() to throw a descriptive exception when no steps exist
2. Updating FormsStepsListBuilder to catch this exception gracefully.

markwk’s picture

Attaching fix that addresses the InvalidArgumentException issue by:
- Adding proper exception handling in getFirstStep() and getLastStep() methods when no steps are available
- Catching the exception in the list builder to prevent crashes when displaying the operations