Commit 658cf84b authored by catch's avatar catch
Browse files

fix: #3562759 ContentEntityBase::hasTranslationChanges() must use loadRevisionUnchanged()

By: berdir
By: amateescu
(cherry picked from commit ff724645)
parent c72febb0
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1488,8 +1488,8 @@ public function hasTranslationChanges() {
    if (!$original) {
      $id = $this->getOriginalId() ?? $this->id();
      $storage = $this->entityTypeManager()->getStorage($this->getEntityTypeId());
      $original = !$this->wasDefaultRevision()
        ? $storage->loadRevision($this->getLoadedRevisionId())
      $original = $this->getLoadedRevisionId() && $storage instanceof RevisionableStorageInterface
        ? $storage->loadRevisionUnchanged($this->getLoadedRevisionId())
        : $storage->loadUnchanged($id);
    }

+23 −2
Original line number Diff line number Diff line
@@ -97,8 +97,29 @@ public function testHasTranslationChanges(): void {

    // Check that the revision metadata fields and the changed field have been
    // skipped when comparing different revisions.
    $entity = $storage->loadRevision($entity_previous_rev_id);
    $this->assertFalse($entity->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges() found no changes when comparing different revisions.');
    $revision = $storage->loadRevision($entity_previous_rev_id);
    $this->assertFalse($revision->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges() found no changes when comparing different revisions.');

    $entity->set('name', 'updated name');
    $entity->setNewRevision(TRUE);
    $this->assertTrue($entity->hasTranslationChanges());
    $entity->save();

    // The old revision should still not report changes.
    $this->assertFalse($revision->hasTranslationChanges());

    // Create a draft revision, should have changes before saving, but not
    // after reloading.
    $entity->set('name', 'draft name');
    $entity->setNewRevision(TRUE);
    $entity->isDefaultRevision(TRUE);
    $this->assertTrue($entity->hasTranslationChanges());
    $entity->save();

    $draft = $storage->loadRevision($entity->getRevisionId());
    $this->assertFalse($draft->hasTranslationChanges());
    $draft->set('name', 'draft name update');
    $this->assertTrue($draft->hasTranslationChanges());
  }

}