You are here

function etuf_latest_revision in Entity Translation Unified Form 8

Retrieve the latest node revision of $lang.

2 calls to etuf_latest_revision()
_custom_shutdown in ./entity_translation_unified_form.module
Helper function for doing stuff after shutdown function to ensure previous db transaction is committed. Make sure the moderation state is processed correctly.
_custom_shutdown_menu in ./entity_translation_unified_form.module
Helper function for doing stuff after shutdown function to ensure previous db transaction is committed. Make sure the moderation state is processed correctly. The main point of this function is to make or update an alias for the other language record…

File

./entity_translation_unified_form.module, line 1248

Code

function etuf_latest_revision($id, &$vid, $lang, $entity_type = 'node') {
  $query = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->getQuery();
  $query
    ->latestRevision();
  if ($entity_type == 'node') {
    $query
      ->condition('nid', $id, '=');
  }
  if ($entity_type == 'taxonomy_term') {
    $query
      ->condition('tid', $id, '=');
  }
  if ($entity_type == 'paragraph') {
    $query
      ->condition('id', $id, '=');
  }
  if ($entity_type == 'user') {

    // Likely no moderation states for user entities anyway but just in case.
    $query
      ->condition('uid', $id, '=');
  }
  $latestRevisionResult = $query
    ->execute();
  if (count($latestRevisionResult)) {
    $node_revision_id = key($latestRevisionResult);
    $vid = $node_revision_id;
    $latestRevision = \Drupal::entityTypeManager()
      ->getStorage($entity_type)
      ->loadRevision($node_revision_id);
    if ($latestRevision
      ->hasTranslation($lang) && $latestRevision
      ->language()
      ->getId() != $lang) {
      $latestRevision = $latestRevision
        ->getTranslation($lang);
    }
    return $latestRevision;
  }
  return FALSE;
}