public function WorkflowTypeBase::setTransitionFromStates in Drupal 10
Same name and namespace in other branches
- 8 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionFromStates()
- 9 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionFromStates()
File
- core/
modules/ workflows/ src/ Plugin/ WorkflowTypeBase.php, line 410
Class
- WorkflowTypeBase
- A base class for Workflow type plugins.
Namespace
Drupal\workflows\PluginCode
public function setTransitionFromStates($transition_id, array $from_state_ids) {
if (!$this
->hasTransition($transition_id)) {
throw new \InvalidArgumentException("The transition '{$transition_id}' does not exist in workflow.");
}
// Ensure that the states exist.
foreach ($from_state_ids as $from_state_id) {
if (!$this
->hasState($from_state_id)) {
throw new \InvalidArgumentException("The state '{$from_state_id}' does not exist in workflow.");
}
if ($this
->hasTransitionFromStateToState($from_state_id, $this->configuration['transitions'][$transition_id]['to'])) {
$existing_transition_id = $this
->getTransitionIdFromStateToState($from_state_id, $this->configuration['transitions'][$transition_id]['to']);
if ($transition_id !== $existing_transition_id) {
throw new \InvalidArgumentException("The '{$existing_transition_id}' transition already allows '{$from_state_id}' to '{$this->configuration['transitions'][$transition_id]['to']}' transitions in workflow.");
}
}
}
// Preserve the order of the state IDs in the from value and don't save any
// keys.
$from_state_ids = array_values($from_state_ids);
sort($from_state_ids);
$this->configuration['transitions'][$transition_id]['from'] = $from_state_ids;
return $this;
}