You are here

public function WorkflowTypeBase::setStateWeight in Drupal 8

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

Sets a state's weight value.

Parameters

string $state_id: The state ID to set the weight for.

int $weight: The state's weight.

Return value

$this

Overrides WorkflowTypeInterface::setStateWeight

1 method overrides WorkflowTypeBase::setStateWeight()
PredefinedStatesWorkflowTestType::setStateWeight in core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/PredefinedStatesWorkflowTestType.php
Sets a state's weight value.

File

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

Class

WorkflowTypeBase
A base class for Workflow type plugins.

Namespace

Drupal\workflows\Plugin

Code

public function setStateWeight($state_id, $weight) {
  if (!$this
    ->hasState($state_id)) {
    throw new \InvalidArgumentException("The state '{$state_id}' does not exist in workflow.");
  }
  if (!is_numeric($weight)) {
    $label = $this
      ->getState($state_id)
      ->label();
    throw new \InvalidArgumentException("The weight '{$weight}' must be numeric for state '{$label}'.");
  }
  $this->configuration['states'][$state_id]['weight'] = $weight;
  return $this;
}