function workflow_revert_workflow_history_alter in Workflow 7
Same name and namespace in other branches
- 7.2 workflow_revert/workflow_revert.module \workflow_revert_workflow_history_alter()
Implements hook_workflow_history_alter(). Add an 'undo' operation for the most recent history change.
Parameters
$variables: The current workflow history information as an array. 'old_sid' - The state ID of the previous state. 'old_state_name' - The state name of the previous state. 'sid' - The state ID of the current state. 'state_name' - The state name of the current state. 'history' - The row from the workflow_node_history table.
If you want to add additional data, place it in the 'extra' value.
File
- workflow_revert/
workflow_revert.module, line 114 - Adds an 'Revert' link to the first workflow history row.
Code
function workflow_revert_workflow_history_alter(&$variables) {
static $first = TRUE;
// Only mark the first row.
if ($first) {
$first = FALSE;
// Let's ask other modules if the reversion is allowed.
$node = node_load($variables['history']->nid);
$result = module_invoke_all('workflow', 'transition permitted', $variables['sid'], $variables['old_sid'], $node);
// Did anybody veto this choice?
if (!in_array(FALSE, $result)) {
// If not vetoed, mark it.
$options = array(
'query' => array(
'token' => drupal_get_token('workflow_revert ' . $variables['old_sid']),
),
);
$path = 'workflow_revert/' . $variables['history']->nid . '/' . $variables['old_sid'];
$variables['extra'] = l('Revert state change', $path, $options);
}
}
}