Score:0

How can I load the transitions for a particular workflow?

in flag

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.

Score:0
in flag

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());
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.