public function StateFlowEntity::entity_saved in State Machine 7.3
Called by hook_entity_insert() / hook_entity_update().
Parameters
string $key: The event name.
int $uid: The user id this event is fired for.
string $log: The log message for the history.
Return value
bool TRUE if successful, FALSE otherwise.
See also
_state_flow_entity_entity_update()
File
- modules/
state_flow_entity/ plugins/ state_flow_entity.inc, line 559 - State Flow implementation of the State Machine class.
Class
- StateFlowEntity
- @file State Flow implementation of the State Machine class.
Code
public function entity_saved($key, $uid = NULL, $log = '') {
$entity = $this
->get_object();
$is_drafty_forward_revision = !empty($entity->revision) && !empty($entity->is_new_revision) && !empty($entity->default_revision);
if (!$is_drafty_forward_revision && ($event = $this
->get_event($key))) {
// Ensure the proper id's are set.
$history_entity = $this
->get_history_entity();
$history_entity->entity_id = $entity->{$this
->get_entity_id_key()};
$history_entity->revision_id = $entity->{$this
->get_revision_key()};
$history_entity->event = $key;
// Ensure we create a new history entry for new revisions.
if (!empty($entity->revision)) {
unset($history_entity->hid);
}
$this
->set_history_entity($history_entity);
// Write a history record for this state change.
$this
->write_history($uid, $log);
// Set this revision as active and update the current status in the table.
$this
->write_active();
// Allow the event to "finish".
$event
->finish();
// Allow state_flow to provide other hooks or event triggers.
//
// @todo the original hook in 7.x-2.x looks like this:
// state_flow_invoke_event_handlers($this, $key, $uid, $log);
// We should review to see if other code uses this hook and update as
// needed.
state_flow_entity_invoke_event_handlers($entity, $this
->get_current_state(), $this
->get_history_entity());
}
elseif ($is_drafty_forward_revision) {
// Forward the history entities.
$this
->forward_history($entity->state_machine_loaded_revision, $entity->{$this
->get_revision_key()});
}
else {
$this
->on_event_fail($event);
return FALSE;
}
}