Commit 619017f1 authored by Dries's avatar Dries

- Patch #1612014 by aspilicious, Berdir: create an interface for revisionable entities.

parent 4f62dcc3
......@@ -252,6 +252,10 @@ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE)
}
}
$query->fields('revision', $entity_revision_fields);
// Compare revision id of the base and revision table, if equal then this
// is the current revision.
$query->addExpression('base.' . $this->revisionKey . ' = revision.' . $this->revisionKey, 'isCurrentRevision');
}
$query->fields('base', $entity_fields);
......
......@@ -38,6 +38,13 @@ class Entity implements EntityInterface {
*/
protected $enforceIsNew;
/**
* Indicates whether this is the current revision.
*
* @var bool
*/
public $isCurrentRevision = TRUE;
/**
* Constructs a new entity object.
*/
......@@ -248,4 +255,19 @@ public function createDuplicate() {
public function entityInfo() {
return entity_get_info($this->entityType);
}
/**
* Implements Drupal\entity\EntityInterface::getRevisionId().
*/
public function getRevisionId() {
return NULL;
}
/**
* Implements Drupal\entity\EntityInterface::isCurrentRevision().
*/
public function isCurrentRevision() {
return $this->isCurrentRevision;
}
}
......@@ -187,4 +187,22 @@ public function createDuplicate();
* @see entity_get_info()
*/
public function entityInfo();
/**
* Returns the revision identifier of the entity.
*
* @return
* The revision identifier of the entity, or NULL if the entity does not
* have a revision identifier.
*/
public function getRevisionId();
/**
* Checks if this entity is the current revision.
*
* @return bool
* TRUE if the entity is the current revision, FALSE otherwise.
*/
public function isCurrentRevision();
}
......@@ -167,4 +167,11 @@ public function createDuplicate() {
$duplicate->vid = NULL;
return $duplicate;
}
/**
* Overrides Drupal\entity\Entity::getRevisionId().
*/
public function getRevisionId() {
return $this->vid;
}
}
......@@ -149,6 +149,9 @@ protected function saveRevision(EntityInterface $entity) {
}
// Make sure to update the new revision key for the entity.
$entity->{$this->revisionKey} = $record->{$this->revisionKey};
// Mark this revision as the current one.
$entity->isCurrentRevision = TRUE;
}
/**
......
......@@ -75,6 +75,9 @@ function testRevisions() {
$this->assertText($log, t('Log message found.'));
}
// Confirm that this is the current revision.
$this->assertTrue($node->isCurrentRevision(), 'Third node revision is the current one.');
// Confirm that revisions revert properly.
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
$this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
......@@ -83,6 +86,10 @@ function testRevisions() {
$reverted_node = node_load($node->nid);
$this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.'));
// Confirm that this is not the current version.
$node = node_load($node->nid, $node->vid);
$this->assertFalse($node->isCurrentRevision(), 'Third node revision is not the current one.');
// Confirm revisions delete properly.
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
......
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