You are here

protected function EntityOperations::isDefaultRevisionPublished in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 src/EntityOperations.php \Drupal\workbench_moderation\EntityOperations::isDefaultRevisionPublished()

Check if the default revision for the given entity is published.

The default revision is the same as the entity retrieved by "default" from the storage handler. If the entity is translated, use the default revision of the same language as the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being saved.

Return value

bool TRUE if the default revision is published. FALSE otherwise.

1 call to EntityOperations::isDefaultRevisionPublished()
EntityOperations::entityPresave in src/EntityOperations.php
Acts on an entity and set published status based on the moderation state.

File

src/EntityOperations.php, line 267

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\workbench_moderation

Code

protected function isDefaultRevisionPublished(EntityInterface $entity) {
  $storage = $this->entityTypeManager
    ->getStorage($entity
    ->getEntityTypeId());
  $default_revision = $storage
    ->load($entity
    ->id());

  // Ensure we are comparing the same translation as the current entity.
  if ($default_revision instanceof TranslatableInterface && $default_revision
    ->isTranslatable()) {

    // If there is no translation, then there is no default revision and is
    // therefore not published.
    if (!$default_revision
      ->hasTranslation($entity
      ->language()
      ->getId())) {
      return FALSE;
    }
    $default_revision = $default_revision
      ->getTranslation($entity
      ->language()
      ->getId());
  }
  return $default_revision && $default_revision->moderation_state->entity
    ->isPublishedState();
}