protected function EntityModeratedRevision::revisionHasPublishedTranslation in Acquia Content Hub 8.2
Checks if the revision has at least one published translation.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity revision being saved.
Return value
bool TRUE if this revision has a published translation, FALSE otherwise.
1 call to EntityModeratedRevision::revisionHasPublishedTranslation()
- EntityModeratedRevision::isPublishedRevision in modules/
acquia_contenthub_publisher/ src/ EntityModeratedRevision.php - Determines whether an entity revision is "published".
File
- modules/
acquia_contenthub_publisher/ src/ EntityModeratedRevision.php, line 146
Class
- EntityModeratedRevision
- Determines whether an entity revision is "published".
Namespace
Drupal\acquia_contenthub_publisherCode
protected function revisionHasPublishedTranslation(EntityInterface $entity) : bool {
$status = $entity
->getEntityType()
->hasKey("status") ? $entity
->getEntityType()
->getKey("status") : NULL;
if (!$status || !$entity instanceof RevisionableInterface) {
// If the entity does not have a publishing status then
// it is considered published.
return TRUE;
}
$definition = $entity
->getFieldDefinition($status);
$property = $definition
->getFieldStorageDefinition()
->getMainPropertyName();
// Ensure we are checking all translations of the revision to be saved.
if ($entity instanceof TranslatableInterface && $entity
->isTranslatable()) {
// Loop through each language that has a translation.
foreach ($entity
->getTranslationLanguages() as $language) {
// Load the translated revision.
$translation = $entity
->getTranslation($language
->getId());
$is_published = $translation
->get($status)->{$property};
if ($is_published) {
return TRUE;
}
}
}
// Entity is not translatable, just return its publishing status.
return (bool) $entity
->get($status)->{$property};
}