drupal_get_destination

5 common.inc drupal_get_destination()
6 common.inc drupal_get_destination()
7 common.inc drupal_get_destination()
8 common.inc drupal_get_destination()

Prepares a 'destination' URL query parameter for use with 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 also

drupal_goto()

Related topics

28 calls to drupal_get_destination()

File

includes/common.inc, line 510
Common functions that many Drupal modules will need to reference.

Code

function drupal_get_destination() {
  $destination = &drupal_static(__FUNCTION__);

  if (isset($destination)) {
    return $destination;
  }

  if (isset($_GET['destination'])) {
    $destination = array('destination' => $_GET['destination']);
  }
  else {
    $path = $_GET['q'];
    $query = drupal_http_build_query(drupal_get_query_parameters());
    if ($query != '') {
      $path .= '?' . $query;
    }
    $destination = array('destination' => $path);
  }
  return $destination;
}

Comments

Works in D6 with Views, but not in D7

I'm trying to redirect users back to a Panels page after creating a new content item, but in D7 I cannot get the proper destination. Here is the code which I insert into a view header:

<?php
global $base_url;
$destination = drupal_get_destination();
$url = $base_url . '/node/add/discount-product?';
print
'<a class="add-new" id="add-new-discount-product" href="' . $url . $destination . '">Add new Discount Product</a>';
?>

D6 returns the destination properly, but D7 returns "Array"

drupal_get_destination()

drupal_get_destination() returns an array in Drupal 7, but returned a string in Drupal 6, so what you want is

<?php
print '<a class="add-new" id="add-new-discount-product" href="' . $url . '?destination=' . $destination['destination'] . '">Add new Discount Product</a>';
?>

Really though, what you want is:

<?php
$options
= array(
 
'query' => drupal_get_destination(),
 
'attributes' => array(
   
'class' => array('add-new'),
   
'id' => 'add-new-discount-product',
  ),
);
print
l(t('Add new Discount Product'), $url, $options);
?>

that's it

$destination = drupal_get_destination();
$destination = $destination['destination'];

Login or register to post comments