From cfc27b446447bc04bb3eed997e981a705abfa043 Mon Sep 17 00:00:00 2001
From: Bram Goffings <bramgoffings@gmail.com>
Date: Sun, 3 Jun 2012 20:02:33 +0200
Subject: [PATCH 2/2] revision interface stuff

---
 core/modules/entity/lib/Drupal/entity/Entity.php   |   15 +++++++++++++
 .../entity/lib/Drupal/entity/EntityController.php  |    3 ++
 .../entity/lib/Drupal/entity/EntityInterface.php   |   18 ++++++++++++++++
 core/modules/node/lib/Drupal/node/Node.php         |   22 ++++++++++++++++++++
 .../lib/Drupal/node/Tests/NodeRevisionsTest.php    |    7 ++++++
 5 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/core/modules/entity/lib/Drupal/entity/Entity.php b/core/modules/entity/lib/Drupal/entity/Entity.php
index f0f5a76..e6355f9 100644
--- a/core/modules/entity/lib/Drupal/entity/Entity.php
+++ b/core/modules/entity/lib/Drupal/entity/Entity.php
@@ -249,4 +249,19 @@ class Entity implements EntityInterface {
   public function entityInfo() {
     return entity_get_info($this->entityType);
   }
+
+  /**
+   * Implements Drupal\entity\EntityInterface::getVersionId().
+   */
+  public function getVersionId() {
+    return NULL;
+  }
+
+  /**
+   * Implements Drupal\entity\EntityInterface::isCurrentVersion().
+   */
+  public function isCurrentVersion() {
+    return TRUE;
+  }
+
 }
diff --git a/core/modules/entity/lib/Drupal/entity/EntityController.php b/core/modules/entity/lib/Drupal/entity/EntityController.php
index 3edc4cc..c3d749a 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityController.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityController.php
@@ -252,6 +252,9 @@ class EntityController implements EntityControllerInterface {
         }
       }
       $query->fields('revision', $entity_revision_fields);
+
+      // Add the active revision.
+      $query->addField('base', $this->revisionKey, $this->revisionKey . '_current');
     }
 
     $query->fields('base', $entity_fields);
diff --git a/core/modules/entity/lib/Drupal/entity/EntityInterface.php b/core/modules/entity/lib/Drupal/entity/EntityInterface.php
index c4c44c2..c241415 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityInterface.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityInterface.php
@@ -182,4 +182,22 @@ interface EntityInterface {
    * @see entity_get_info()
    */
   public function entityInfo();
+
+  /**
+   * Returns the version identifier of the entity.
+   *
+   * @return
+   *   The version identifier of the entity, or NULL if the entity does not have
+   *   a version identifier.
+   */
+  public function getVersionId();
+
+  /**
+   * Checks if this entity is the active version.
+   *
+   * @return bool
+   *   TRUE if the entity is the active version, FALSE otherwise.
+   */
+  public function isCurrentVersion();
+
 }
diff --git a/core/modules/node/lib/Drupal/node/Node.php b/core/modules/node/lib/Drupal/node/Node.php
index 0e8347b..ef705b2 100644
--- a/core/modules/node/lib/Drupal/node/Node.php
+++ b/core/modules/node/lib/Drupal/node/Node.php
@@ -29,6 +29,14 @@ class Node extends Entity {
   public $vid;
 
   /**
+   * The active node revision ID.
+   *
+   * @var integer
+   */
+  public $vid_current;
+
+
+  /**
    * The node content type (bundle).
    *
    * @var string
@@ -167,4 +175,18 @@ class Node extends Entity {
     $duplicate->vid = NULL;
     return $duplicate;
   }
+
+  /**
+   * Overrides Drupal\entity\Entity::getVersionId().
+   */
+  public function getVersionId() {
+    return $this->vid;
+  }
+
+  /**
+   * Overrides Drupal\entity\Entity::isCurrentVersion().
+   */
+  public function isCurrentVersion() {
+    return $this->vid == $this->vid_current;
+  }
 }
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php
index c7f29fa..0b1379a 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php
@@ -75,6 +75,9 @@ class NodeRevisionsTest extends NodeTestBase {
       $this->assertText($log, t('Log message found.'));
     }
 
+    // Confirm that this is the current version
+    $this->assertTrue($node->isCurrentVersion(), 'Third node revision is the active 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 @@ class NodeRevisionsTest extends NodeTestBase {
     $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->isCurrentVersion(), 'Third node revision is not the active 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.',
-- 
1.7.4.msysgit.0

