function workflownode_node_insert in Workflow 7.2
Implements hook_node_insert().
This is executed after saving data to the database. We cannot use hook_node_presave, because workflow_execute_transition() needs the nid.
File
- workflow_node/
workflownode.module, line 144 - Hooks and functions for the 'conventional' (version D5/D6/D7.1) Workflow Node, remnants of nodeapi.
Code
function workflownode_node_insert($node) {
global $user;
if (!isset($node->workflow_field)) {
// Initializing the state of the node in case no widget on Node form.
if ($workflow = workflow_get_workflows_by_type($node->type, 'node')) {
$comment = t('Set to initial state.');
$force = TRUE;
$creation_sid = $workflow
->getCreationSid();
// Get the initial state for this node.
// Due to permissions, it might be different for each user.
$new_sid = $workflow
->getFirstSid('node', $node, null, $user, $force);
$transition = new WorkflowTransition();
$transition
->setValues('node', $node, null, $creation_sid, $new_sid, $user->uid, REQUEST_TIME, $comment);
// Force it to transition to the first state and get a history record.
workflow_execute_transition('node', $node, null, $transition, $force);
}
}
return workflownode_node_update($node);
}