You are here

protected function EntityOperations::isPublished in Drupal 8

Same name and namespace in other branches
  1. 9 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_moderation

Code

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;
}