function EntityOperations::isPublished
Same name in other branches
- 9 core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::isPublished()
- 8.9.x core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::isPublished()
- 11.x core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::isPublished()
Checks if the entity is published.
This method is optimized to not have to unnecessarily load the moderation state and workflow if it is not required.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to check.
Return value
bool TRUE if the entity is published, FALSE otherwise.
1 call to EntityOperations::isPublished()
- EntityOperations::entityView in core/
modules/ content_moderation/ src/ EntityOperations.php - Act on entities being assembled before rendering.
File
-
core/
modules/ content_moderation/ src/ EntityOperations.php, line 311
Class
- EntityOperations
- Defines a class for reacting to entity events.
Namespace
Drupal\content_moderationCode
protected function isPublished(ContentEntityInterface $entity) {
// If the entity implements EntityPublishedInterface directly, check that
// first, otherwise fall back to check through the workflow state.
if ($entity instanceof EntityPublishedInterface) {
return $entity->isPublished();
}
if ($moderation_state = $entity->get('moderation_state')->value) {
$workflow = $this->moderationInfo
->getWorkflowForEntity($entity);
return $workflow->getTypePlugin()
->getState($moderation_state)
->isPublishedState();
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.