protected EntityOperations::isDefaultRevisionPublished(EntityInterface $entity)
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.
File
- core/modules/content_moderation/src/EntityOperations.php, line 246
Class
- EntityOperations
- Defines a class for reacting to entity events.
Namespace
Drupal\content_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(); }
Please login to continue.