use Drupal\Core\Entity\EntityInterface;
use Drupal\workflows\WorkflowInterface;
// Load the entity (e.g., a node).
$entity = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
// Get the workflow associated with the entity.
$workflow_manager = \Drupal::service('workflows.manager');
$workflow = $workflow_manager->getWorkflowForEntity($entity);
if ($workflow instanceof WorkflowInterface) {
// Get the current state of the entity.
$current_state = $workflow->getState($entity);
if ($current_state) {
// Get possible transitions from the current state.
$possible_transitions = $current_state->getTransitions();
// Loop through possible transitions and gather information.
foreach ($possible_transitions as $transition) {
$transition_id = $transition->getId();
$transition_label = $transition->getLabel();
// Do something with the transition ID and label.
}
}
}