You are here

state_flow_node.inc in State Machine 7.3

State Flow implementation of the State Machine class

File

modules/state_flow/plugins/state_flow_node.inc
View source
<?php

/**
 * @file
 * State Flow implementation of the State Machine class
 */

/**
 * Class StateFlowNode.
 *
 * Handles node entities.
 */
class StateFlowNode extends StateFlowEntity {

  /**
   * Callback for when an entity enters the unpublished state.
   *
   * Make sure this revision is the one going to the node table.
   */
  public function on_enter_published() {
    $this->object->published_revision_id = $this->object->{$this
      ->get_revision_key()};
    $this->object->status = 1;
  }

  /**
   * Callback for when a node enters the unpublished state.
   *
   * Make sure this revision is the one going to the node table.
   */
  public function on_enter_unpublished() {

    // "published_revision_id" is somewhat of a misnomer here. It's really
    // "the revision_id that is in the node table."
    $this->object->published_revision_id = $this->object->{$this
      ->get_revision_key()};
    $this->object->revision = FALSE;
    $this->object->state_flow_node_on_enter_unpublished = TRUE;
  }
  public function on_exit_published() {

    // If it is a scheduled event the transition has to be handled later because
    // we want to keep the current state.
    $event = $this
      ->get_event($this
      ->get_history_entity()->event);
    if ($event
      ->get_option('target') !== 'schedule') {
      $this->object->status = 0;
    }
  }

  /**
   * Handle unpublishing / publishing.
   *
   * Usually StateFlowNode::on_exit_published() handles this - but since
   * scheduling shouldn't change the state during scheduling we do it here too.
   *
   * @see StateFlowNode::on_exit_published()
   */
  public function on_exit_scheduled() {

    // Fire the previously skipped hook.
    $this
      ->on_exit_published();
    parent::on_exit_scheduled();
  }

  /**
   * Provide the current state of this revision or entity.
   *
   * @return string
   *   Machine name of a state.
   */
  public function load() {
    $state = parent::load();

    // When State Flow is installed on an existing site there may be nodes
    // already published. Those nodes should be considered as "published" by
    // State Flow.
    if (empty($state) && !empty($this->object->status) && !empty($this->object->nid)) {
      return 'published';
    }
    return $state;
  }

}

Classes

Namesort descending Description
StateFlowNode Class StateFlowNode.