function ContentEntityStorageBase::isAnyStoredRevisionTranslated

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::isAnyStoredRevisionTranslated()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::isAnyStoredRevisionTranslated()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::isAnyStoredRevisionTranslated()

Checks whether any stored entity revision is translated.

A revisionable entity can have translations in a pending revision, hence the default revision may appear as not translated. This determines whether the entity has any translation in the storage and thus should be considered as multilingual.

Parameters

\Drupal\Core\Entity\TranslatableInterface $entity: The entity object to be checked.

Return value

bool TRUE if the entity has at least one translation in any revision, FALSE otherwise.

See also

\Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages()

\Drupal\Core\Entity\ContentEntityStorageBase::isAnyRevisionTranslated()

1 call to ContentEntityStorageBase::isAnyStoredRevisionTranslated()
ContentEntityStorageBase::isAnyRevisionTranslated in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Checks whether any entity revision is translated.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 321

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function isAnyStoredRevisionTranslated(TranslatableInterface $entity) {
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    if ($entity->isNew()) {
        return FALSE;
    }
    if ($entity instanceof TranslationStatusInterface) {
        foreach ($entity->getTranslationLanguages(FALSE) as $langcode => $language) {
            if ($entity->getTranslationStatus($langcode) === TranslationStatusInterface::TRANSLATION_EXISTING) {
                return TRUE;
            }
        }
    }
    $query = $this->getQuery()
        ->condition($this->entityType
        ->getKey('id'), $entity->id())
        ->condition($this->entityType
        ->getKey('default_langcode'), 0)
        ->accessCheck(FALSE)
        ->range(0, 1);
    if ($entity->getEntityType()
        ->isRevisionable()) {
        $query->allRevisions();
    }
    $result = $query->execute();
    return !empty($result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.