function ContentEntityStorageBase::getLatestRevisionId

Returns the latest revision identifier for an entity.

Parameters

int|string $entity_id: The entity identifier.

Return value

int|string|null The latest revision identifier or NULL if no revision could be found.

Overrides RevisionableStorageInterface::getLatestRevisionId

1 call to ContentEntityStorageBase::getLatestRevisionId()
ContentEntityStorageBase::getLatestTranslationAffectedRevisionId in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Returns the latest revision affecting the specified translation.

File

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

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.