function WorkflowTypeBase::setStateWeight

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

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

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