You are here

function publishcontent_toggle_status in Publish Content 7

Same name and namespace in other branches
  1. 5.2 publishcontent.module \publishcontent_toggle_status()
  2. 5 publishcontent.module \publishcontent_toggle_status()
  3. 6 publishcontent.module \publishcontent_toggle_status()

Menu callback for publish / unpublish content actions.

Parameters

node $node: A node object.

1 call to publishcontent_toggle_status()
publishcontent_toggle_status_form_submit in ./publishcontent.module
Submit handler for Publish/Unpublish confirmation form

File

./publishcontent.module, line 321
Add link to publish or unpublish a node, with access control based on the node type

Code

function publishcontent_toggle_status($node) {

  // XOR the current status with 1 to get the opposite value.
  $node->status = $node->status ^ 1;

  // 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;
  }

  // Save the status we want to set.
  $status = $node->status;

  // Try to update the node.
  node_save($node);

  // Validate the status has changed.
  if ($status == $node->status) {

    // Everything went well.
    drupal_set_message(_publishcontent_get_message($node->nid, $node->title, $node->status));
  }
  else {

    // Prevent the user something went wrong.
    drupal_set_message(t('The status of the node could not be updated.'), 'error');
  }

  // Clear the page and block caches.
  cache_clear_all();
  drupal_goto('node/' . $node->nid);
}