You are here

public function WorkflowTypeBase::addState in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addState()
  2. 9 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addState()
1 method overrides WorkflowTypeBase::addState()
PredefinedStatesWorkflowTestType::addState in core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/PredefinedStatesWorkflowTestType.php
Adds a state to the workflow.

File

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

Class

WorkflowTypeBase
A base class for Workflow type plugins.

Namespace

Drupal\workflows\Plugin

Code

public function addState($state_id, $label) {
  if ($this
    ->hasState($state_id)) {
    throw new \InvalidArgumentException("The state '{$state_id}' already exists in workflow.");
  }
  if (preg_match(static::VALID_ID_REGEX, $state_id)) {
    throw new \InvalidArgumentException("The state ID '{$state_id}' must contain only lowercase letters, numbers, and underscores");
  }
  $this->configuration['states'][$state_id] = [
    'label' => $label,
    'weight' => $this
      ->getNextWeight($this->configuration['states']),
  ];
  ksort($this->configuration['states']);
  return $this;
}