public function WorkflowTypeBase::addState in Drupal 8
Same name and namespace in other branches
- 9 core/modules/workflows/src/Plugin/WorkflowTypeBase.php \Drupal\workflows\Plugin\WorkflowTypeBase::addState()
Adds a state to the workflow.
Parameters
string $state_id: The state's ID.
string $label: The state's label.
Return value
$this
Throws
\InvalidArgumentException Thrown if a state already exists or state ID is invalid.
Overrides WorkflowTypeInterface::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\PluginCode
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;
}