function WorkflowTypeBase::addTransition
Same name in other branches
- 8.9.x core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addTransition()
- 10 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addTransition()
- 11.x core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addTransition()
Overrides WorkflowTypeInterface::addTransition
File
-
core/
modules/ workflows/ src/ Plugin/ WorkflowTypeBase.php, line 227
Class
- WorkflowTypeBase
- A base class for Workflow type plugins.
Namespace
Drupal\workflows\PluginCode
public function addTransition($transition_id, $label, array $from_state_ids, $to_state_id) {
if ($this->hasTransition($transition_id)) {
throw new \InvalidArgumentException("The transition '{$transition_id}' already exists in workflow.");
}
if (preg_match(static::VALID_ID_REGEX, $transition_id)) {
throw new \InvalidArgumentException("The transition ID '{$transition_id}' must contain only lowercase letters, numbers, and underscores.");
}
if (!$this->hasState($to_state_id)) {
throw new \InvalidArgumentException("The state '{$to_state_id}' does not exist in workflow.");
}
$this->configuration['transitions'][$transition_id] = [
'label' => $label,
'from' => [],
'to' => $to_state_id,
// Always add to the end.
'weight' => $this->getNextWeight($this->configuration['transitions']),
];
try {
$this->setTransitionFromStates($transition_id, $from_state_ids);
} catch (\InvalidArgumentException $e) {
unset($this->configuration['transitions'][$transition_id]);
throw $e;
}
ksort($this->configuration['transitions']);
return $this;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.