diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php
index 066f6fb..e25b24c 100644
--- a/core/lib/Drupal/Core/Entity/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -299,10 +299,10 @@ public function __construct($definition) {
// Ensure defaults.
$this->entity_keys += [
'revision' => '',
- 'latest_revision' => 'latest_revision',
'bundle' => '',
'langcode' => '',
'default_langcode' => 'default_langcode',
+ 'latest_revision' => 'latest_revision',
];
$this->handlers += [
'access' => 'Drupal\Core\Entity\EntityAccessControlHandler',
diff --git a/core/lib/Drupal/Core/Entity/RevisionableInterface.php b/core/lib/Drupal/Core/Entity/RevisionableInterface.php
index 4c569d7..ca27e50 100644
--- a/core/lib/Drupal/Core/Entity/RevisionableInterface.php
+++ b/core/lib/Drupal/Core/Entity/RevisionableInterface.php
@@ -33,7 +33,7 @@ public function setNewRevision($value = TRUE);
/**
* Gets the revision identifier of the entity.
*
- * @return
+ * @return int
* The revision identifier of the entity, or NULL if the entity does not
* have a revision identifier.
*/
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
index cfbd971..55fe89d 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
@@ -97,6 +97,9 @@ protected function getExpectedNormalizedEntity() {
'vid' => [
['value' => 1],
],
+ 'latest_revision' => [
+ ['value' => 1],
+ ],
'langcode' => [
[
'value' => 'en',
diff --git a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php
index 71fa6b3..e1070b0 100644
--- a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php
+++ b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php
@@ -120,6 +120,9 @@ public function testNormalize() {
'revision_id' => [
['value' => 1],
],
+ 'latest_revision' => [
+ ['value' => 1],
+ ],
'default_langcode' => [
['value' => TRUE],
],
@@ -191,6 +194,7 @@ public function testSerialize() {
'created' => '' . $this->entity->created->value . '',
'user_id' => '' . $this->user->id() . '' . $this->user->getEntityTypeId() . '' . $this->user->uuid() . '' . $this->user->url() . '',
'revision_id' => '' . $this->entity->getRevisionId() . '',
+ 'latest_revision' => '' . $this->entity->getLatestRevisionId() . '',
'default_langcode' => '1',
'non_rev_field' => '',
'field_test_text' => '' . $this->values['field_test_text']['value'] . '' . $this->values['field_test_text']['format'] . '',
diff --git a/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php b/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php
index f2e8632..53cf0fd 100644
--- a/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php
+++ b/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php
@@ -28,15 +28,6 @@ public function testLatestRevisionUpgradePath() {
$this->runUpdates();
// @todo, add some more entity types.
-
- // mysql> select name, id, revision_id, latest_revision from test58485450entity_test_mulrev_property_data;
- // +-----------------------+----+-------------+-----------------+
- // | name | id | revision_id | latest_revision |
- // +-----------------------+----+-------------+-----------------+
- // | Three revisions | 1 | 3 | 3 |
- // | Two forward revisions | 2 | 4 | 6 |
- // +-----------------------+----+-------------+-----------------+
-
$three_revisions = EntityTestMulRev::load(1);
$this->assertEqual(3, $three_revisions->getLatestRevisionId());
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLatestRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLatestRevisionTest.php
index 77584b3..1303a31 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLatestRevisionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLatestRevisionTest.php
@@ -3,6 +3,7 @@
namespace Drupal\KernelTests\Core\Entity;
use Drupal\entity_test\Entity\EntityTestMulRev;
+use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the latest revision tracking.
@@ -20,6 +21,7 @@ class EntityLatestRevisionTest extends EntityKernelTestBase {
'system',
'entity_test',
'language',
+ 'content_translation',
];
/**
@@ -36,6 +38,9 @@ protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test_mulrev');
$this->storage = $this->container->get('entity_type.manager')->getStorage('entity_test_mulrev');
+
+ $this->installConfig(['language']);
+ ConfigurableLanguage::createFromLangcode('de')->save();
}
/**
@@ -44,7 +49,7 @@ protected function setUp() {
public function testLatestRevision() {
// Until saved, the latest revision should be null.
$entity = EntityTestMulRev::create([]);
- $this->assertEquals(null, $entity->getLatestRevisionId());
+ $this->assertEquals(NULL, $entity->getLatestRevisionId());
// Once saved, the latest revision will be be set.
$entity->save();
@@ -60,4 +65,30 @@ public function testLatestRevision() {
$this->assertEquals(2, $revision_1->getLatestRevisionId());
}
+ /**
+ * Test the latest revision tracking with translations.
+ */
+ public function testWithTranslations() {
+ $entity = EntityTestMulRev::create([]);
+ $entity->save();
+ $this->assertEquals(1, $entity->getLatestRevisionId());
+ $this->assertEquals(1, $entity->getRevisionId());
+
+ // Adding a translation will create another revision of the same ID, so
+ // the latest revision ID should also be the same.
+ $translated_entity = $entity->addTranslation('de');
+ $translated_entity->save();
+ $this->assertEquals(1, $translated_entity->getLatestRevisionId());
+ $this->assertEquals(1, $translated_entity->getRevisionId());
+
+ // Create a forward revision for the translated entity.
+ $translated_entity->setNewRevision(TRUE);
+ $translated_entity->isDefaultRevision(FALSE);
+ $translated_entity->save();
+
+ // The latest revision should be incremented for both languages.
+ $this->assertEquals(2, $translated_entity->getLatestRevisionId());
+ $this->assertEquals(2, EntityTestMulRev::load(1)->getLatestRevisionId());
+ }
+
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
index d1045f5..0e17181 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -58,7 +58,7 @@ public function testSet($key, $value) {
*/
public function testGetKeys($entity_keys, $expected) {
$entity_type = $this->setUpEntityType(['entity_keys' => $entity_keys]);
- $this->assertSame($expected + ['default_langcode' => 'default_langcode'], $entity_type->getKeys());
+ $this->assertSame($expected + ['default_langcode' => 'default_langcode', 'latest_revision' => 'latest_revision'], $entity_type->getKeys());
}
/**