From d323590cce5989f02b2b550b46bc0fd709550ff8 Mon Sep 17 00:00:00 2001
From: Bram Goffings <bramgoffings@gmail.com>
Date: Sun, 3 Jun 2012 16:49:59 +0200
Subject: [PATCH 2/2] revision 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 ++++++++++++++++++++
 4 files changed, 58 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..f3305be 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;
+  }
 }
-- 
1.7.4.msysgit.0

