You are here

public function Workflow::getTransitions in Workflow 8

Loads all allowed ConfigTransitions for this workflow.

Parameters

array|null $ids: Array of Transitions IDs. If NULL, show all transitions.

array $conditions: $conditions['from_sid'] : if provided, a 'from' State ID. $conditions['to_sid'] : if provided, a 'to' state ID.

Return value

\Drupal\workflow\Entity\WorkflowConfigTransition[]

Overrides WorkflowInterface::getTransitions

2 calls to Workflow::getTransitions()
Workflow::getTransitionsById in src/Entity/Workflow.php
Workflow::getTransitionsByStateId in src/Entity/Workflow.php
Get a specific transition.

File

src/Entity/Workflow.php, line 431

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function getTransitions(array $ids = NULL, array $conditions = []) {
  $config_transitions = [];

  // Get filters on 'from' states, 'to' states, roles.
  $from_sid = isset($conditions['from_sid']) ? $conditions['from_sid'] : FALSE;
  $to_sid = isset($conditions['to_sid']) ? $conditions['to_sid'] : FALSE;

  // Get valid states + creation state.
  $states = $this
    ->getStates('CREATION');

  // Cache all transitions in the workflow.
  if (!$this->transitions) {
    $this->transitions = WorkflowConfigTransition::loadMultiple($ids);
    $this
      ->sortTransitions();
  }

  /** @var \Drupal\workflow\Entity\WorkflowConfigTransition $config_transition */
  foreach ($this->transitions as &$config_transition) {
    if (!isset($states[$config_transition
      ->getFromSid()])) {

      // Not a valid transition for this workflow. @todo Delete them.
    }
    elseif ($from_sid && $from_sid != $config_transition
      ->getFromSid()) {

      // Not the requested 'from' state.
    }
    elseif ($to_sid && $to_sid != $config_transition
      ->getToSid()) {

      // Not the requested 'to' state.
    }
    else {

      // Transition is allowed, permitted. Add to list.
      $config_transitions[$config_transition
        ->id()] = $config_transition;
    }
  }
  return $config_transitions;
}