function workbench_moderation_set_node_state in Workbench Moderation 7.3
Loads moderation information onto a node being saved.
2 calls to workbench_moderation_set_node_state()
- workbench_moderation_entity_presave in ./
workbench_moderation.module - Implements hook_entity_presave().
- workbench_moderation_save in ./
workbench_moderation.module - Saves the moderation history for the node.
File
- ./
workbench_moderation.module, line 711 - Content moderation for Workbench.
Code
function workbench_moderation_set_node_state($node) {
global $user;
// Set moderation state values.
if (!isset($node->workbench_moderation_state_current)) {
$node->workbench_moderation_state_current = !empty($node->original->workbench_moderation['current']->state) ? $node->original->workbench_moderation['current']->state : workbench_moderation_state_none();
}
if (!isset($node->workbench_moderation_state_new)) {
// Moderating the default revision. Capture the proper state from drafty.
if (!empty($node->default_revision) && $node->status) {
$node->workbench_moderation_state_new = workbench_moderation_state_published();
}
elseif ($node->status == NODE_NOT_PUBLISHED && isset($node->original->status) && $node->original->status == NODE_PUBLISHED) {
// @todo Currently we cannot set the state correctly if the default state
// is "Published".
// @see https://www.drupal.org/node/1436260
$node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none());
}
elseif ($node->status == NODE_PUBLISHED && isset($node->original->status) && $node->original->status == NODE_NOT_PUBLISHED) {
$node->workbench_moderation_state_new = workbench_moderation_state_published();
}
else {
if (!empty($node->original->workbench_moderation['current']->state)) {
$node->workbench_moderation_state_new = $node->original->workbench_moderation['current']->state;
}
else {
$node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none());
}
}
}
// If this is a new node, give it some information about 'my revision'.
if (!isset($node->workbench_moderation)) {
$node->workbench_moderation = array();
$node->workbench_moderation['my_revision'] = $node->workbench_moderation['current'] = (object) array(
'from_state' => workbench_moderation_state_none(),
'state' => workbench_moderation_state_none(),
'nid' => $node->nid,
'vid' => $node->vid,
'uid' => $user->uid,
'is_current' => TRUE,
'published' => FALSE,
'stamp' => $node->changed,
);
}
}