I need to validate unpublished status in hook_node_presave.
If my hook prevents node from been unpublished, the status message does not correspond to the actual status of the node.
My patch is:
function publishcontent_toggle_status($node) {
// XOR the current status with 1 to get the opposite value.
$node->status = $node->status ^ 1;
/** SAVE THE INITIAL VALUE STATUS */
$trytoset = $node->status;
// If this content type specifies that a new revision should be created on
// editing, then make sure to respect this option.
$node_options = variable_get('node_options_' . $node->type, array());
if (in_array('revision', $node_options)) {
$node->revision = 1;
}
node_save($node);
/** CHECK STATUS */
if ($trytoset==$node->status)
drupal_set_message(_publishcontent_get_message($node->nid, $node->title, $node->status));
drupal_goto($_SERVER['HTTP_REFERER']);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | publishcontent-node_couldnt_be_updated-1790188-7648763.patch | 906 bytes | johnennew |
| #2 | publishcontent-node_couldnt_be_updated-1790188-7265606.patch | 904 bytes | johnennew |
| #1 | publishcontent-1790188-1-node_couldnt_be_updated.patch | 899 bytes | simon georges |
Comments
Comment #1
simon georges commentedThe patch corresponding to the post above, so people could test it more easily.
Comment #2
johnennew commentedRerolled for latest dev branch. Doesn't appear to break anything.
Comment #3
johnennew commentedAnother reroll
Comment #4
johnennew commentedCommitted to 7.x-1.x