function ContentEntityStorageBase::getLatestTranslationAffectedRevisionId

Returns the latest revision affecting the specified translation.

Parameters

int|string $entity_id: The entity identifier.

string $langcode: The language code of the translation.

Return value

int|string|null A revision ID or NULL if no revision affecting the specified translation could be found.

Overrides TranslatableRevisionableStorageInterface::getLatestTranslationAffectedRevisionId

File

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

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function getLatestTranslationAffectedRevisionId($entity_id, $langcode) {
  if (!$this->entityType
    ->isRevisionable()) {
    return NULL;
  }
  if (!$this->entityType
    ->isTranslatable()) {
    return $this->getLatestRevisionId($entity_id);
  }
  $cached = $this->memoryCache
    ->get("latest_revision_id:{$this->entityTypeId}:{$entity_id}");
  $latest_revision_ids = $cached ? $cached->data : [];
  if (!isset($latest_revision_ids[$langcode])) {
    $result = $this->getQuery()
      ->allRevisions()
      ->condition($this->entityType
      ->getKey('id'), $entity_id)
      ->condition($this->entityType
      ->getKey('revision_translation_affected'), 1, '=', $langcode)
      ->range(0, 1)
      ->sort($this->entityType
      ->getKey('revision'), 'DESC')
      ->accessCheck(FALSE)
      ->addMetaData('entity_id', $entity_id)
      ->addTag('latest_translated_affected_revision')
      ->execute();
    $latest_revision_ids[$langcode] = key($result);
    $this->memoryCache
      ->set("latest_revision_id:{$this->entityTypeId}:{$entity_id}", $latest_revision_ids, MemoryCacheInterface::CACHE_PERMANENT, [
      $this->memoryCacheTag,
    ]);
  }
  return $latest_revision_ids[$langcode];
}

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