You are here

public function StateFlow::fire_event in State Machine 7

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

Extending fire_event() from state_machine's base.inc to add uid and log arguments.

Overrides StateMachine::fire_event

File

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

Class

StateFlow

Code

public function fire_event($key, $uid = NULL, $log = '') {
  $event = $this
    ->get_event($key);
  if ($event && ($new_state = $event
    ->execute())) {

    // Allow the previous state to run its 'on_exit' callbacks.
    $this
      ->get_state($this
      ->get_current_state())
      ->on_exit();

    // Set and save the new state.
    $this
      ->set_current_state($new_state);
    $this
      ->persist();

    // Write a history record for this state change.
    if (empty($uid)) {
      global $user;
      $uid = $user->uid;
    }
    $this
      ->write_history($uid, $log);

    // Allow the new state to run its 'on_enter' callbacks.
    $this
      ->get_state($this
      ->get_current_state())
      ->on_enter();

    // Allow the event to "finish".
    $event
      ->finish();

    // Allow state_flow to provide other hooks or event triggers.
    state_flow_invoke_event_handlers($this->object, $new_state);
  }
  else {
    $this
      ->on_event_fail($event);
    return FALSE;
  }
}