You are here

public function StateFlow::init in State Machine 7

Same name and namespace in other branches
  1. 6 modules/state_flow/plugins/state_flow.inc \StateFlow::init()
  2. 7.2 modules/state_flow/plugins/state_flow.inc \StateFlow::init()

Called from StateMachine::__construct to initialize the states and events. Define two states. First revision:

  • Expose go to draft button
  • Expose go to publish button
  • Upon publish, create new revision (handled outside of state machine)

Second revision:

  • Menu alter edit link to load most recent revision (whether published or revision from states)
  • On hook_nodeapi (op: load), force new revision checkbox on node edit form
    • Expose go to draft button
  • Create new revision, prevent node table from updating new revision as published revision
  • Expose go to publish button
  • Upon publish, set revision id in node table
  • Repeat as needed

Overrides StateMachine::init

1 method overrides StateFlow::init()
StateFlowTest::init in modules/state_flow/state_flow.api.php
* Override the init method to set the new states * * Add a to review state and "Review" event

File

modules/state_flow/plugins/state_flow.inc, line 27

Class

StateFlow

Code

public function init() {

  // Initialize states
  $this
    ->create_state('draft');
  $this
    ->create_state('published', array(
    'on_enter' => array(
      $this,
      'on_enter_published',
    ),
    'on_exit' => array(
      $this,
      'on_exit_published',
    ),
  ));
  $this
    ->create_state('unpublished');

  // Initialize events
  $this
    ->create_event('publish', array(
    'origin' => 'draft',
    'target' => 'published',
  ));
  $this
    ->create_event('unpublish', array(
    'origin' => 'published',
    'target' => 'unpublished',
    'permission' => 'publish and unpublish content',
  ));
  $this
    ->create_event('to draft', array(
    'origin' => 'unpublished',
    'target' => 'draft',
  ));
}