Untitled
unknown
plain_text
a year ago
931 B
2
Indexable
Never
use Drupal\workflows\WorkflowManager; use Drupal\Core\Entity\EntityInterface; // Assuming you have the entity and its workflow ID. /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = ...; $workflow_id = 'your_workflow_id'; // Get the workflow manager service. $workflow_manager = \Drupal::service('workflows.manager'); $workflow = $workflow_manager->getWorkflowById($workflow_id); // Get the current state. $current_state = $workflow->getState($entity); // Get available transitions from the current state. $transitions = $current_state->getTransitions(); // Collect roles associated with these transitions. $roles_involved = []; foreach ($transitions as $transition) { foreach ($transition->get('to_states') as $state_id) { $state = $workflow->getState($state_id); $roles_involved += $state->get('roles'); } } // Now $roles_involved contains the roles associated with the next possible transitions.