public function Workflow::createState in Workflow 8
Create a new state for this workflow.
Parameters
string $sid:
bool $save: Indicator if the new state must be saved. Normally, the new State is saved directly in the database. This is because you can use States only with Transitions, and they rely on State IDs which are generated magically when saving the State. But you may need a temporary state.
Return value
\Drupal\workflow\Entity\WorkflowState The new state.
Overrides WorkflowInterface::createState
1 call to Workflow::createState()
- Workflow::getCreationState in src/
Entity/ Workflow.php - Gets the initial state for a newly created entity.
File
- src/
Entity/ Workflow.php, line 245
Class
- Workflow
- Workflow configuration entity to persistently store configuration.
Namespace
Drupal\workflow\EntityCode
public function createState($sid, $save = TRUE) {
$wid = $this
->id();
/** @var \Drupal\workflow\Entity\WorkflowState $state */
$state = WorkflowState::load($sid);
if (!$state || $wid != $state
->getWorkflowId()) {
$values = [
'id' => $sid,
'wid' => $wid,
];
$state = WorkflowState::create($values);
if ($save) {
$state
->save();
}
}
// Maintain the new object in the workflow.
$this->states[$state
->id()] = $state;
return $state;
}