diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 3475ad8002f16c3663fba838444aa97bfd93db04..1895cfdf1e195386da7f61f6b15b0aa2dbba0380 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -933,7 +933,7 @@ public function createDuplicate() { } // Check whether the entity type supports revisions and initialize it if so. - if ($entity_type->hasKey('revision')) { + if ($entity_type->isRevisionable()) { $duplicate->{$entity_type->getKey('revision')}->value = NULL; } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 1a55637a87039cecb1479fef316161f3e368eb96..27c8e789663ba33dc9d0aa2f2c35fafed5cae474 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -102,8 +102,7 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa // Check if the entity type supports UUIDs. $this->uuidKey = $this->entityType->getKey('uuid'); - // Check if the entity type supports revisions. - if ($this->entityType->hasKey('revision')) { + if ($this->entityType->isRevisionable()) { $this->revisionKey = $this->entityType->getKey('revision'); $this->revisionTable = $this->entityType->getRevisionTable(); } diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index de4411cc930983ca4d28c6c8f85a5584c429985d..653864743e63dcf88c38a189d3860a769f5f7304 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -545,6 +545,14 @@ public function isTranslatable() { return !empty($this->translatable); } + /** + * {@inheritdoc} + */ + public function isRevisionable() { + // Entity types are revisionable if a revision key has been specified. + return $this->hasKey('revision'); + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 7706a58c6a9e178a505340e1bdd6961ec4ac63ef..a6e39aa7a070197a5713b0a6b24fbaa1fb1b08ea 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -85,8 +85,8 @@ public function getClass(); * property and its value must be numeric. * - revision: (optional) The name of the property that contains the * revision ID of the entity. The Field API assumes that all revision IDs - * are unique across all entities of a type. This entry can be omitted if - * the entities of this type are not versionable. + * are unique across all entities of a type. If this entry is omitted + * the entities of this type are not revisionable. * - bundle: (optional) The name of the property that contains the bundle * name for the entity. The bundle name defines which set of fields are * attached to the entity (e.g. what nodes call "content type"). This @@ -541,6 +541,13 @@ public function getBaseTable(); */ public function isTranslatable(); + /** + * Indicates whether entities of this type have revision support. + * + * @return bool + */ + public function isRevisionable(); + /** * Returns the config prefix used by the configuration entity type. * diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php index ef9bd2e707504497492af937af298930053057e5..162b937239829a8acaecd332819fed774517e54a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php @@ -142,10 +142,8 @@ public function testCreate() { ->method('getKeys') ->will($this->returnValue(array('id' => 'id'))); $entity_type->expects($this->atLeastOnce()) - ->method('hasKey') - ->will($this->returnCallback(function ($key) { - return $key == 'id'; - })); + ->method('isRevisionable') + ->will($this->returnValue(FALSE)); $entity_manager->expects($this->atLeastOnce()) ->method('getDefinition') ->with('test_entity_type') diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 1cb561c6e76aa2ac512706d2b9b7d96a2a6a77b2..ac29654c7737cb6a94ebaf2b2f1cf54872b7b60e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -88,6 +88,18 @@ public function providerTestGetKeys() { ); } + /** + * Tests the isRevisionable() method. + */ + public function testIsRevisionable() { + $entity_type = $this->setUpEntityType(array('entity_keys' => array('id' => 'id'))); + $this->assertFalse($entity_type->isRevisionable()); + $entity_type = $this->setUpEntityType(array('entity_keys' => array('id' => 'id', 'revision' => FALSE))); + $this->assertFalse($entity_type->isRevisionable()); + $entity_type = $this->setUpEntityType(array('entity_keys' => array('id' => 'id', 'revision' => TRUE))); + $this->assertTrue($entity_type->isRevisionable()); + } + /** * Tests the getController() method. */