Commit 31387c5a authored by Dries's avatar Dries

- Patch #26467 by drumm: make the destination persist across multiple pages

  and fixed the node delete form to use a return destination.
parent 02ca763e
......@@ -133,20 +133,28 @@ function drupal_get_headers() {
/**
* Prepare a destination query string for use in combination with
* drupal_goto(). Used to direct the user back to the referring page
* after completing a form.
* drupal_goto(). Used to direct the user back to the referring page
* after completing a form. By default the current URL is returned.
* If a destination exists in the previous request, that destination
* is returned. As such, a destination can persist across multiple
* pages.
*
* @see drupal_goto()
*/
function drupal_get_destination() {
$destination[] = $_GET['q'];
$params = array('page', 'sort', 'order');
foreach ($params as $param) {
if (isset($_GET[$param])) {
$destination[] = "$param=". $_GET[$param];
if ($_REQUEST['destination']) {
return 'destination='. urlencode($_REQUEST['destination']);
}
else {
$destination[] = $_GET['q'];
$params = array('page', 'sort', 'order');
foreach ($params as $param) {
if (isset($_GET[$param])) {
$destination[] = "$param=". $_GET[$param];
}
}
return 'destination='. urlencode(implode('&', $destination));
}
return 'destination='. urlencode(implode('&', $destination));
}
/**
......
......@@ -673,7 +673,7 @@ function node_menu($may_cache) {
'weight' => 1,
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'node/'. arg(1) .'/delete', 'title' => t('delete'),
'callback' => 'node_page',
'callback' => 'node_delete_page',
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
......@@ -1696,27 +1696,35 @@ function node_page() {
return node_preview($edit);
}
break;
case 'delete':
case t('Delete'):
// Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
if ($_GET['q'] == 'node/'. arg(1) .'/edit') {
if ($_REQUEST['destination']) {
$destination = drupal_get_destination();
unset($_REQUEST['destination']);
drupal_goto('node/'. arg(1) .'/delete');
}
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$output = node_delete($edit);
if (!$output) {
drupal_set_message(t('The node has been deleted.'));
drupal_goto('admin/node');
}
return node_delete($edit);
break;
drupal_goto('node/'. arg(1) .'/delete', $destination);
default:
drupal_set_title('');
return node_page_default();
}
}
/**
* Menu callback; the page for deleting a single node.
*/
function node_delete_page() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (!($output = node_delete($edit))) {
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
drupal_goto('');
}
return $output;
}
/**
* Implementation of hook_update_index().
*/
......
......@@ -673,7 +673,7 @@ function node_menu($may_cache) {
'weight' => 1,
'type' => MENU_LOCAL_TASK);
$items[] = array('path' => 'node/'. arg(1) .'/delete', 'title' => t('delete'),
'callback' => 'node_page',
'callback' => 'node_delete_page',
'access' => node_access('delete', $node),
'weight' => 1,
'type' => MENU_CALLBACK);
......@@ -1696,27 +1696,35 @@ function node_page() {
return node_preview($edit);
}
break;
case 'delete':
case t('Delete'):
// Note: we redirect from node/uid/edit to node/uid/delete to make the tabs disappear.
if ($_GET['q'] == 'node/'. arg(1) .'/edit') {
if ($_REQUEST['destination']) {
$destination = drupal_get_destination();
unset($_REQUEST['destination']);
drupal_goto('node/'. arg(1) .'/delete');
}
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$output = node_delete($edit);
if (!$output) {
drupal_set_message(t('The node has been deleted.'));
drupal_goto('admin/node');
}
return node_delete($edit);
break;
drupal_goto('node/'. arg(1) .'/delete', $destination);
default:
drupal_set_title('');
return node_page_default();
}
}
/**
* Menu callback; the page for deleting a single node.
*/
function node_delete_page() {
$edit = $_POST['edit'];
$edit['nid'] = $edit['nid'] ? $edit['nid'] : arg(1);
$node = node_load($edit['nid']);
if (!($output = node_delete($edit))) {
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', $node->title))));
drupal_goto('');
}
return $output;
}
/**
* Implementation of hook_update_index().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment