diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 4f11f1e..81a6c2f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -1173,10 +1173,11 @@ public function hasTranslationChanges() { // possible or be meaningless. /** @var \Drupal\Core\Entity\ContentEntityBase $translation */ $translation = $original->getTranslation($this->activeLangcode); + $revision_field_name = $this->getEntityType()->getKey('revision') ?: 'revision_id'; foreach ($this->getFieldDefinitions() as $field_name => $definition) { // @todo Avoid special-casing the following fields. See // https://www.drupal.org/node/2329253. - if ($field_name == 'revision_translation_affected' || $field_name == 'revision_id') { + if ($field_name == 'revision_translation_affected' || $field_name == $revision_field_name) { continue; } if (!$definition->isComputed() && (!$translated || $definition->isTranslatable())) { diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityHasChangesTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityHasChangesTest.php new file mode 100644 index 0000000..63d70ab --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityHasChangesTest.php @@ -0,0 +1,75 @@ +installEntitySchema('node'); + $this->installSchema('node', 'node_access'); + $this->installEntitySchema('user'); + + // Create a new node-type. + NodeType::create([ + 'type' => $this->bundle, + 'name' => $this->randomString(), + ])->save(); + } + + /** + * Tests the correct functionality of the hasTranslationChanges function. + * + */ + public function testHasTranslationChanges() { + $node = Node::create([ + 'type' => $this->bundle, + 'title' => $this->randomString(), + ]); + $node->save(); + + $this->assertFalse($node->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges found no changes after the entity has been saved.'); + + $node_previous_rev_id = $node->getRevisionId(); + $node->setNewRevision(TRUE); + $node->save(); + + /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */ + $storage = $this->container->get('entity_type.manager') + ->getStorage('node'); + $node = $storage->loadRevision($node_previous_rev_id); + + $this->assertFalse($node->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges found no changes on the old revision.'); + } + +}