function WorkflowTypeBase::setTransitionFromStates

Same name and namespace in other branches
  1. 9 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionFromStates()
  2. 8.9.x core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionFromStates()
  3. 10 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionFromStates()

Overrides WorkflowTypeInterface::setTransitionFromStates

2 calls to WorkflowTypeBase::setTransitionFromStates()
WorkflowTypeBase::addTransition in core/modules/workflows/src/Plugin/WorkflowTypeBase.php
Adds a transition to the workflow.
WorkflowTypeBase::deleteState in core/modules/workflows/src/Plugin/WorkflowTypeBase.php
Deletes a state from the workflow.

File

core/modules/workflows/src/Plugin/WorkflowTypeBase.php, line 410

Class

WorkflowTypeBase
A base class for Workflow type plugins.

Namespace

Drupal\workflows\Plugin

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.