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']);
}

Comments

simon georges’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new899 bytes

The patch corresponding to the post above, so people could test it more easily.

johnennew’s picture

Rerolled for latest dev branch. Doesn't appear to break anything.

johnennew’s picture

Another reroll

johnennew’s picture

Status: Needs review » Fixed

Committed to 7.x-1.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.