0

I want to load the transition objects for a Workflow. In Drupal 8, I see a Workflow::getTransitions() method, however it seems this method was removed in Drupal 9.

1 Answer 1

1

The easiest way to do this is through the workflow's type plugin, specifically the getTransitions() method.

// First load a workflow, for example:
$workflow = \Drupal::service('content_moderation.moderation_information')
  ->getWorkflowForEntity($entity);

// Then get the workflow's type plugin.
/** @var \Drupal\workflows\WorkflowTypeInterface $workflow_type_plugin */
$workflow_type_plugin = $workflow->getTypePlugin();

// Finally, load the transitions.
$workflow_transitions = $workflow_type_plugin->getTransitions();

Alternatively, it may be more useful to only get the valid transitions for an entity, i.e. only transitions allowed for the entity from its current state, for the current user. The getValidTransitions() method from the content_moderation.state_transition_validation service does this.

/** @var \Drupal\content_moderation\StateTransitionValidationInterface $transition_validation */
$transition_validation = \Drupal::service('content_moderation.state_transition_validation');
$valid_transitions = $transition_validation
  ->getValidTransitions($entity, \Drupal::currentUser());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.