You are here

public function Drafty::getPublishedRevisionId in Drafty 7

Get the current published revision for an entity.

Parameters

$type: The entity type.

$id: The entity ID.

Return value

A version ID.

File

./drafty.module, line 229
Hook implementations and API functions for the Drafty module.

Class

Drafty
Handles tracking, selecting and publishing revisions.

Code

public function getPublishedRevisionId($type, $id) {
  $info = entity_get_info();

  // Get the version ID of the published revision directly from the database.
  // It is not possible to rely on $entity->original here since that does not
  // guarantee being the published revision. Also avoid loading the entity
  // because we may be in the process of saving it.
  $query = db_select($info[$type]['base table'], 'b');
  $query
    ->addField('b', $info[$type]['entity keys']['revision']);
  $query
    ->condition($info[$type]['entity keys']['id'], $id);
  $vid = $query
    ->execute()
    ->fetchField();
  return $vid;
}