getLatestTranslationAffectedRevisionId example

// Load the created entity and create a new pending revision.     $pending_revision = EntityTestMulRev::load($entity->id());
    $pending_revision->setName($this->randomString());
    $pending_revision->setNewRevision(TRUE);
    $pending_revision->isDefaultRevision(FALSE);

    // Check that no revision affecting Italian is available, given that no     // Italian translation has been created yet.     /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
    $this->assertNull($storage->getLatestTranslationAffectedRevisionId($entity->id(), 'it'));
    $this->assertEquals($pending_revision->getLoadedRevisionId()$storage->getLatestRevisionId($entity->id()));

    // The pending revision should still be marked as the latest affected one     // before it is saved.     $this->assertTrue($pending_revision->isLatestTranslationAffectedRevision());
    $pending_revision->save();
    $this->assertTrue($pending_revision->isLatestTranslationAffectedRevision());

    // Load the default revision and check that it is not marked as the latest     // (translation-affected) revision.     $default_revision = EntityTestMulRev::load($entity->id());
    

  protected function createRevision(ContentEntityInterface $translation$default = TRUE) {
    if (!$translation->isNewTranslation()) {
      $langcode = $translation->language()->getId();
      $revision_id = $this->storage->getLatestTranslationAffectedRevisionId($translation->id()$langcode);
      /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
      $revision = $this->storage->loadRevision($revision_id);
      $translation = $revision->getTranslation($langcode);
    }
    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    $revision = $this->storage->createRevision($translation$default);
    return $revision;
  }

  /** * Asserts that the expected violations were found. * * @param \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations * A list of violations. * * @internal */

  }

  /** * {@inheritdoc} */
  public function hasPendingRevision(ContentEntityInterface $entity) {
    $result = FALSE;
    if ($this->isModeratedEntity($entity)) {
      /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
      $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
      $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$entity->language()->getId());
      $default_revision_id = $entity->isDefaultRevision() && !$entity->isNewRevision() && ($revision_id = $entity->getRevisionId()) ?
        $revision_id : $this->getDefaultRevisionId($entity->getEntityTypeId()$entity->id());
      if ($latest_revision_id !== NULL && $latest_revision_id != $default_revision_id) {
        /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */
        $latest_revision = $storage->loadRevision($latest_revision_id);
        $result = !$latest_revision->wasDefaultRevision();
      }
    }
    return $result;
  }

  
foreach ($languages as $language) {
        $language_name = $language->getName();
        $langcode = $language->getId();

        // If the entity type is revisionable, we may have pending revisions         // with translations not available yet in the default revision. Thus we         // need to load the latest translation-affecting revision for each         // language to be sure we are listing all available translations.         if ($use_latest_revisions) {
          $entity = $default_revision;
          $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$langcode);
          if ($latest_revision_id) {
            /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */
            $latest_revision = $storage->loadRevision($latest_revision_id);
            // Make sure we do not list removed translations, i.e. translations             // that have been part of a default revision but no longer are.             if (!$latest_revision->wasDefaultRevision() || $default_revision->hasTranslation($langcode)) {
              $entity = $latest_revision;
            }
          }
          $translations = $entity->getTranslationLanguages();
        }

        
return $result;
    }

    $config = ContentLanguageSettings::load($entity_type_id . '.' . $entity->bundle());
    $result->addCacheableDependency($config);
    if (!$this->contentTranslationManager->isEnabled($entity_type_id$entity->bundle())) {
      return $result;
    }

    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$entity->language()->getId());
    if (!$revision_id) {
      return $result;
    }

    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    $revision = $storage->loadRevision($revision_id);
    if ($revision->wasDefaultRevision()) {
      return $result;
    }

    $result = $result->andIf(AccessResult::forbidden());
    

  protected function loadRevisionTranslation(ContentEntityInterface $entity$langcode) {
    // Explicitly invalidate the cache for that node, as the call below is     // statically cached.     $this->storage->resetCache([$entity->id()]);
    $revision_id = $this->storage->getLatestTranslationAffectedRevisionId($entity->id()$langcode);
    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    $revision = $revision_id ? $this->storage->loadRevision($revision_id) : NULL;
    return $revision && $revision->hasTranslation($langcode) ? $revision->getTranslation($langcode) : NULL;
  }

  /** * Returns the edit URL for the specified entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity being edited. * * @return \Drupal\Core\Url * The edit URL. */
$previous_untranslatable_field_value = $this->previousUntranslatableFieldValue[$previous_untranslatable_field_langcode];
    }

    // Check that after instantiating a new revision for the specified     // translation, we are resuming work from where we left the last time. If     // that is the case, the label generated for the previous revision should     // match the stored one.     if (!$entity->isNew()) {
      $previous_label = NULL;
      if (!$entity->isNewTranslation()) {
        $previous_label = $this->generateNewEntityLabel($entity$previous_revision_id);
        $latest_affected_revision_id = $this->storage->getLatestTranslationAffectedRevisionId($entity->id()$entity->language()->getId());
      }
      else {
        // Normally it would make sense to load the default revision in this         // case, however that would mean simulating here the logic that we need         // to test, thus "masking" possible flaws. To avoid that, we simply         // pretend we are starting from an earlier non translated revision.         // This ensures that the we can check that the merging logic is applied         // also when adding a new translation.         $latest_affected_revision_id = 1;
      }
      $previous_revision_id = (int) $entity->getLoadedRevisionId();
      

  protected function getLatestTranslationAffectedRevision(RevisionableInterface $entity$langcode) {
    $revision = NULL;
    $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());

    if ($entity instanceof TranslatableRevisionableInterface && $entity->isTranslatable()) {
      /** @var \Drupal\Core\Entity\TranslatableRevisionableStorageInterface $storage */
      $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$langcode);

      // If the latest translation-affecting revision was a default revision, it       // is fine to load the latest revision instead, because in this case the       // latest revision, regardless of it being default or pending, will always       // contain the most up-to-date values for the specified translation. This       // provides a BC behavior when the route is defined by a module always       // expecting the latest revision to be loaded and to be the default       // revision. In this particular case the latest revision is always going       // to be the default revision, since pending revisions would not be       // supported.       $revision = $revision_id ? $this->loadRevision($entity$revision_id) : NULL;
      
return $this->getLoadedRevisionId() == $storage->getLatestRevisionId($this->id());
  }

  /** * {@inheritdoc} */
  public function isLatestTranslationAffectedRevision() {
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager()->getStorage($this->getEntityTypeId());

    return $this->getLoadedRevisionId() == $storage->getLatestTranslationAffectedRevisionId($this->id()$this->language()->getId());
  }

  /** * {@inheritdoc} */
  public function isRevisionTranslationAffected() {
    return $this->hasField($this->revisionTranslationAffectedKey) ? $this->get($this->revisionTranslationAffectedKey)->value : TRUE;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.