function workflow_actions_workflow in Workflow 6.2
Same name and namespace in other branches
- 6 workflow_actions/workflow_actions.module \workflow_actions_workflow()
- 7.2 workflow_actions/workflow_actions.module \workflow_actions_workflow()
- 7 workflow_actions/workflow_actions.module \workflow_actions_workflow()
Implementation of hook_workflow().
Parameters
$op: The current workflow operation: 'transition pre' or 'transition post'.
$old_state: The state ID of the current state.
$new_state: The state ID of the new state.
$node: The node whose workflow state is changing.
File
- workflow_actions/
workflow_actions.module, line 175 - Provide actions and triggers for workflows. Why it's own module? Some sites prefer rules, some prefer actions, all prefer a lower code footprint and better performance. Additional creadit to gcassie ( http://drupal.org/user/80260 ) for the…
Code
function workflow_actions_workflow($op, $old_state, $new_state, $node) {
switch ($op) {
case 'transition pre':
// The workflow module does nothing during this operation.
// But your module's implementation of the workflow hook could
// return FALSE here and veto the transition.
break;
case 'transition post':
// A transition has occurred; fire off actions associated with this transition.
// Can't fire actions if trigger module is not enabled.
if (!module_exists('trigger')) {
break;
}
$tid = workflow_get_transition_id($old_state, $new_state);
$op = 'workflow-' . $node->type . '-' . $tid;
$aids = _trigger_get_hook_aids('workflow', $op);
if ($aids) {
$context = array(
'hook' => 'workflow',
'op' => $op,
);
// We need to get the expected object if the action's type is not 'node'.
// We keep the object in $objects so we can reuse it if we have multiple actions
// that make changes to an object.
foreach ($aids as $aid => $action_info) {
if ($action_info['type'] != 'node') {
if (!isset($objects[$action_info['type']])) {
$objects[$action_info['type']] = _trigger_normalize_node_context($action_info['type'], $node);
}
// Pass the node as the object for actions of type 'system'.
if (!isset($objects[$action_info['type']]) && $action_info['type'] == 'system') {
$objects[$action_info['type']] = $node;
}
// Since we know about the node, we pass that info along to the action.
$context['node'] = $node;
$result = actions_do($aid, $objects[$action_info['type']], $context);
}
else {
actions_do($aid, $node, $context);
}
}
}
break;
}
}