You are here

protected function StateFlowEntity::isDraftRevision in State Machine 7.3

Check if the current object is a draft revision.

A draft revision is it if:

  • It's already marked as draft revision.
  • It's not a new entity.
  • The currently active revision differs from the entity revision.
  • There is an active revision and a new revision is requested.
  • A requested revision is not published.

Also sets the property is_draft_revision on the entity.

Return value

bool Whether or not the current object is a draft revision.

1 call to StateFlowEntity::isDraftRevision()
StateFlowEntity::entityPresave in modules/state_flow_entity/plugins/state_flow_entity.inc
Called by hook_entity_presave().

File

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

Class

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

Code

protected function isDraftRevision() {
  $entity = $this
    ->get_object();

  // If this somehow was marked as is_draft_revision we don't change this.
  if (empty($entity->is_draft_revision)) {

    // Ensure this has a value - empty() also passes if the property wasn't
    // set yet.
    $entity->is_draft_revision = FALSE;

    // If this revision isn't the published one it's likely a draft.
    $this
      ->set_available_publish_revision();
    if (!$this
      ->object_is_new() && !empty($entity->published_revision_id)) {

      // If the target state is neither published nor unpublished, this is a draft.
      $entity->is_draft_revision = empty($entity->event) || !($event = $this
        ->get_event($entity->event)) || !$event
        ->get_target_state()
        ->is_published() && !$event
        ->get_target_state()
        ->is_unpublished();
    }
  }
  return $entity->is_draft_revision;
}