You are here

public function WorkflowTypeBase::setTransitionWeight in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionWeight()
  2. 10 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::setTransitionWeight()

Sets a transition's weight.

Parameters

string $transition_id: The transition ID.

int $weight: The transition's weight.

Return value

$this

Throws

\InvalidArgumentException Thrown if the transition does not exist.

Overrides WorkflowTypeInterface::setTransitionWeight

File

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

Class

WorkflowTypeBase
A base class for Workflow type plugins.

Namespace

Drupal\workflows\Plugin

Code

public function setTransitionWeight($transition_id, $weight) {
  if (!$this
    ->hasTransition($transition_id)) {
    throw new \InvalidArgumentException("The transition '{$transition_id}' does not exist in workflow.");
  }
  if (!is_numeric($weight)) {
    $label = $this
      ->getTransition($transition_id)
      ->label();
    throw new \InvalidArgumentException("The weight '{$weight}' must be numeric for transition '{$label}'.");
  }
  $this->configuration['transitions'][$transition_id]['weight'] = $weight;
  return $this;
}