You are here

public function StateFlow::init in State Machine 7.2

Same name and namespace in other branches
  1. 6 modules/state_flow/plugins/state_flow.inc \StateFlow::init()
  2. 7 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', array(
    'label' => t('Draft'),
  ));
  $this
    ->create_state('published', array(
    'label' => t('Published'),
    'on_enter' => array(
      $this,
      'on_enter_published',
    ),
    'on_exit' => array(
      $this,
      'on_exit_published',
    ),
  ));
  $this
    ->create_state('unpublished', array(
    'label' => t('Unpublished'),
  ));
  if (module_exists('state_flow_schedule')) {
    $this
      ->create_state('scheduled', array(
      'label' => t('Scheduled'),
      'on_exit' => array(
        $this,
        'on_exit_scheduled',
      ),
    ));
  }

  // Initialize events
  $this
    ->create_event('unpublish', array(
    'label' => t('Unpublish'),
    'origin' => 'published',
    'target' => 'unpublished',
    'permission' => 'publish and unpublish content',
  ));
  $to_draft = array(
    'label' => t('To Draft'),
    'origin' => 'unpublished',
    'target' => 'draft',
  );
  $to_publish = array(
    'label' => t('Publish'),
    'origin' => 'draft',
    'target' => 'published',
  );
  if (module_exists('state_flow_schedule')) {
    $this
      ->create_event('schedule', array(
      'label' => t('Schedule'),
      'origin' => 'draft',
      'target' => 'scheduled',
      'guard' => 'state_flow_guard_schedule',
    ));
    $to_draft['origin'] = array(
      'unpublished',
      'scheduled',
    );
    $to_publish['origin'] = array(
      'draft',
      'scheduled',
    );
  }
  $this
    ->create_event('to draft', $to_draft);
  $this
    ->create_event('publish', $to_publish);
}