I'm copying a custom module using Workflow from D8 to D9 into a new project. At one point we get the "allowed states" of a certain workflow field (in the dossier bundle). In D8 this following code worked perfectly:

  public static function getWorkflowFieldSettings($field) {
    // Get bundle fields.
    $fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'dossier');
    // Check if bundle field with events exists.
    if (isset($fields[$field])) {
      /** @var \Drupal\field\FieldConfigInterface $field_definition */
      $field_definition = $fields[$field];
      // Get field states.
      $states = workflow_state_allowed_values($field_definition->getFieldStorageDefinition());
      if (!empty($states)) {
        $states = ['none' => t('(Creation)')->__toString()] + $states;
      }
      return $states;
    }
    return [];
  }

In D9 this only returns an empty array. What I did find out:
- workflow_state_allowed_values() is kind of a stub function for old functionality (looking at previous issues).
- The bundle dossier is newly created in D9
- When I look in the workflow_state_allowed_values() to the $definition parameter (at runtime), I do see that the 'allowed_values' is an empty array, and allowed_values_function isn't filled in. My guess is that it would have worked if we used the dossier bundle of the old system as 'legacy solution'.

And then the question is how to get the possible states of workflow of a certain field in order to make the code above work.

Comments

sboden created an issue. See original summary.

johnv’s picture

The function was removed, including schema, then the schema was added again....

  • johnv committed fb106da8 on 8.x-1.x
    Issue #3225627 by sboden: workflow_state_allowed_values() breaks in D9
    
johnv’s picture

Version: 8.x-1.5 » 8.x-1.7
Category: Support request » Bug report
Status: Active » Fixed

Sorry for the late reply.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.