| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Unpublish nodes when using the delete function in the node's edit tab.
|
| 7 |
* Content deletion may still actually be done through Content Administration.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_form_alter().
|
| 12 |
*/
|
| 13 |
function recycle_node_form_alter($form_id, &$form) {
|
| 14 |
global $user;
|
| 15 |
// add Unpublish button to the delete node form
|
| 16 |
if ($form_id == 'node_delete_confirm' && $user->uid != 1) {
|
| 17 |
unset($form['#submit']['node_delete_confirm_submit']);
|
| 18 |
$form['#submit']['recycle_node_form_unpublish_submit'] = array();
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
function recycle_node_form_unpublish_submit($form_id, $form_values) {
|
| 23 |
if ($form_id == 'node_delete_confirm') {
|
| 24 |
$node = node_load($form_values['nid']);
|
| 25 |
$node->status = 0; // set status to unpublished
|
| 26 |
node_save($node);
|
| 27 |
drupal_set_message(t("Node @nid has been unpublished.", array('@nid' => $form_values['nid'])));
|
| 28 |
}
|
| 29 |
return '';
|
| 30 |
}
|