You are here

public function Workflow::createTransition in Workflow 8

Creates a Transition for this workflow.

Parameters

string $from_sid:

string $to_sid:

array $values:

Return value

\Drupal\workflow\Entity\WorkflowConfigTransitionInterface

Overrides WorkflowInterface::createTransition

File

src/Entity/Workflow.php, line 396

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function createTransition($from_sid, $to_sid, array $values = []) {
  $config_transition = NULL;

  // First check if this transition already exists.
  $transitions = $this
    ->getTransitionsByStateId($from_sid, $to_sid);
  if ($transitions) {
    $config_transition = reset($transitions);
  }
  else {
    $values['wid'] = $this
      ->id();
    $values['from_sid'] = $from_sid;
    $values['to_sid'] = $to_sid;
    $config_transition = WorkflowConfigTransition::create($values);
    $config_transition
      ->save();
  }

  // Maintain the new object in the workflow.
  $this->transitions[$config_transition
    ->id()] = $config_transition;
  return $config_transition;
}