You are here

public function StateFlowEntity::get_active_revision in State Machine 7.3

Get the active revision.

The active revision is not necessarily the published revision.

@todo I am not sure I like this method. confirm that we need this. There may be a better way.

Return value

int The revision_id.

File

modules/state_flow_entity/plugins/state_flow_entity.inc, line 747
State Flow implementation of the State Machine class.

Class

StateFlowEntity
@file State Flow implementation of the State Machine class.

Code

public function get_active_revision() {
  if (empty($this->object->active_revision_id)) {
    $entity_type = $this
      ->get_entity_type();
    $entity_info = entity_get_info($entity_type);
    $id_key = $entity_info['entity keys']['id'];
    $this->object->active_revision_id = 0;
    if (!$this
      ->object_is_new()) {
      $revision_id = db_select('state_flow_states', 'sfs')
        ->fields('sfs', array(
        'revision_id',
      ))
        ->condition('entity_type', $entity_type)
        ->condition('entity_id', $this->object->{$id_key})
        ->condition('active', 1)
        ->execute()
        ->fetchCol();
      if (!empty($revision_id[0])) {
        $this->object->active_revision_id = $revision_id[0];
      }
    }
  }
  return $this->object->active_revision_id;
}