You are here

protected function LingotekContentTranslationService::loadUploadedRevision in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  2. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  3. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  4. 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  5. 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  6. 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  7. 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  8. 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  9. 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  10. 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()
  11. 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::loadUploadedRevision()

Loads the correct revision is loaded from the database, bypassing caches.

Parameters

ContentEntityInterface $entity: The entity we want to load a revision from.

int|NULL $revision: The revision id. NULL if we don't know it.

Return value

ContentEntityInterface The wanted revision of the entity.

1 call to LingotekContentTranslationService::loadUploadedRevision()
LingotekContentTranslationService::saveTargetData in src/LingotekContentTranslationService.php
Save the entity translation.

File

src/LingotekContentTranslationService.php, line 800
Contains \Drupal\lingotek\LingotekContentTranslationService.

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

protected function loadUploadedRevision(ContentEntityInterface $entity, $revision = NULL) {
  $the_revision = NULL;
  $entity_type = $entity
    ->getEntityType();
  $type = $entity
    ->getEntityTypeId();
  if ($entity_type
    ->isRevisionable()) {

    // If the entity type is revisionable, we need to check the proper revision.
    // This may come from the uploaded data, but in case we didn't have it, we
    // have to infer using the timestamp.
    if ($revision !== NULL) {
      $the_revision = entity_revision_load($type, $revision);
    }
    elseif ($revision === NULL && $entity
      ->hasField('revision_timestamp')) {

      // Let's find the better revision based on the timestamp.
      $timestamp = $this->lingotek
        ->getUploadedTimestamp($this
        ->getDocumentId($entity));
      $revision = $this
        ->getClosestRevisionToTimestamp($entity, $timestamp);
      $the_revision = entity_revision_load($type, $revision);
    }
    else {

      // We didn't find a better option, but let's reload this one so it's not
      // cached.
      $the_revision = entity_revision_load($type, $entity
        ->getRevisionId());
    }
  }
  else {
    $the_revision = entity_load($type, $entity
      ->id(), TRUE);
  }
  return $the_revision;
}