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

8.0.x
Nathaniel Catchpole 2014-05-09 11:11:41 +01:00
parent 5a01a26f15
commit 938ac1f5b7
6 changed files with 33 additions and 9 deletions

View File

@ -933,7 +933,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
}
// 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;
}

View File

@ -102,8 +102,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase {
// 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();
}

View File

@ -545,6 +545,14 @@ class EntityType implements EntityTypeInterface {
return !empty($this->translatable);
}
/**
* {@inheritdoc}
*/
public function isRevisionable() {
// Entity types are revisionable if a revision key has been specified.
return $this->hasKey('revision');
}
/**
* {@inheritdoc}
*/

View File

@ -85,8 +85,8 @@ interface EntityTypeInterface {
* 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 @@ interface EntityTypeInterface {
*/
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.
*

View File

@ -142,10 +142,8 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
->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')

View File

@ -88,6 +88,18 @@ class EntityTypeTest extends UnitTestCase {
);
}
/**
* 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.
*/