function ContentEntityStorageBase::getLatestRevisionId

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

File

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

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function getLatestRevisionId($entity_id) {
  if (!$this->entityType
    ->isRevisionable()) {
    return NULL;
  }
  $cached = $this->memoryCache
    ->get("latest_revision_id:{$this->entityTypeId}:{$entity_id}");
  $latest_revision_ids = $cached ? $cached->data : [];
  if (!isset($latest_revision_ids[LanguageInterface::LANGCODE_DEFAULT])) {
    $result = $this->getQuery()
      ->latestRevision()
      ->condition($this->entityType
      ->getKey('id'), $entity_id)
      ->accessCheck(FALSE)
      ->execute();
    $latest_revision_ids[LanguageInterface::LANGCODE_DEFAULT] = key($result);
    $this->memoryCache
      ->set("latest_revision_id:{$this->entityTypeId}:{$entity_id}", $latest_revision_ids, MemoryCacheInterface::CACHE_PERMANENT, [
      $this->memoryCacheTag,
    ]);
  }
  return $latest_revision_ids[LanguageInterface::LANGCODE_DEFAULT];
}

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