You are here

protected function EntityOperations::isPublished in Config Entity Revisions 8.2

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 src/EntityOperations.php
Act on entities being assembled before rendering.

File

src/EntityOperations.php, line 331

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\config_entity_revisions

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