public function ContentModeration::getInitialState in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration::getInitialState()
Gets the initial state for the workflow.
Return value
\Drupal\workflows\StateInterface The initial state.
Overrides WorkflowTypeBase::getInitialState
File
- core/
modules/ content_moderation/ src/ Plugin/ WorkflowType/ ContentModeration.php, line 303
Class
- ContentModeration
- Attaches workflows to content entity types and their bundles.
Namespace
Drupal\content_moderation\Plugin\WorkflowTypeCode
public function getInitialState($entity = NULL) {
// Workflows are not tied to entities, but Content Moderation adds the
// relationship between Workflows and entities. Content Moderation needs the
// entity object to be able to determine the initial state based on
// publishing status.
if (!$entity instanceof ContentEntityInterface) {
throw new \InvalidArgumentException('A content entity object must be supplied.');
}
if ($entity instanceof EntityPublishedInterface && !$entity
->isNew()) {
return $this
->getState($entity
->isPublished() ? 'published' : 'draft');
}
return $this
->getState(!empty($this->configuration['default_moderation_state']) ? $this->configuration['default_moderation_state'] : 'draft');
}