public function StateMachine::fire_event in State Machine 7.2
Same name and namespace in other branches
- 6 inc/base.inc \StateMachine::fire_event()
- 7.3 inc/base.inc \StateMachine::fire_event()
- 7 inc/base.inc \StateMachine::fire_event()
Trigger an event to process a transition. Callbacks and guard conditions will be processed in the following order:
- event:before_transition
- event:guard, exits if guard condition return FALSE
- oldstate:on_exit
- update the current state
- newstate:on_enter
- event:after_transition
1 method overrides StateMachine::fire_event()
- StateFlow::fire_event in modules/
state_flow/ plugins/ state_flow.inc - Extending fire_event() from state_machine's base.inc to add uid and log arguments.
File
Class
- StateMachine
- @file base.inc
Code
public function fire_event($key) {
$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();
// 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();
}
else {
$this
->on_event_fail($event);
return FALSE;
}
}