WorkflowState and WorkflowTransition should implement interfaces

Created on 11 March 2021, about 4 years ago
Updated 5 April 2025, 19 days ago

Problem/Motivation

NOTICE: PHP message: TypeError: Argument 1 passed to Drupal\state_machine\Plugin\Field\FieldType\StateItem::Drupal\state_machine\Plugin\Field\FieldType\{closure}() must be an instance of Drupal\state_machine\Plugin\Workflow\WorkflowState

You are able to override the default Workflow class by supplying 'workflow_class' on the Workflow Group configuration.

Within the default class constructor arrays of WorkflowState and WorkflowTransition objects are built and stored. These classes are then strictly type hinted within the Form Field and Event code. This means that if you have the need to extend the WorkflowState or WorkflowTransition classes you have to re-write large portions of the From Field and Event code as well.

Steps to reproduce

  • Configure a Workflow Group and Workflow
  • Define a workflow_class override on the Workflow Group configuration
  • Create a new class and Extend the WorkflowState class to add an arbitrary method/property and use object of this new class to populate Workflow $states
  • Try and access the field settings page or an entity with a field instance and you will receive the above error (Or something similar)

Proposed resolution

Create a WorkflowStateInterface and a WorkflowTransitionInterface that is used by the rest of the module for Type Hinting instead of explicitly requiring objects of WorkflowState or WorkflowTransition.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom lind101

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024