Commit 938ac1f5 authored by catch's avatar catch

Issue #2224549 by tstoeckler, fago, Xano: Simplify checking whether an entity type is revisionable.

parent 5a01a26f
......@@ -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;
}
......
......@@ -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();
}
......
......@@ -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}
*/
......
......@@ -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.
*
......
......@@ -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')
......
......@@ -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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment