Drupal Questions & Answers

Ask and answer Drupal related questions! No question too simple or complex!
Torva's picture
Asked by on Fri 3rd Sep 2010
How to get path alias, sanitize, pass to link button?

I tried this code which is a modification of the Drupal function “drupal_get_destination” but it produces a parsing error:

Parse error: syntax error, unexpected T_IF, expecting '{' in /usr/local/www/apache22/data/includes/common.inc(1695) : eval()'d code on line 3

I pasted this code into a Views Custom Field, to be displayed as a link button in a block (I think it’s properly sanitized to prevent a script inserted into URL):

function drupal_get_destination_alias() {
  if (isset(
$_REQUEST['destination'])) {
'destination='. urlencode(drupal_get_path_alias($_REQUEST['destination']));
  else {
// Use $_GET here to retrieve the original path in source form.
$path = isset($_GET['q']) ? $_GET['q'] : '';
$query = drupal_query_string_encode($_GET, array('q'));
    if (
$query != '') {
$path .= '?'. $query;
'destination='. urlencode(drupal_get_path_alias($path));

$path1 = drupal_get_destination_alias();
print (
"<a href=\"" . $path1 . "/buildings\" title=\"View\">View</a>");

The idea is to take the path from the page the Views block display is on, like “content/chicago/southside” and when the button is clicked, take the user to a page with a view with a path like “content/chicago/southside/buildings”. “Chicago” and “southside” are passed as arguments to the view.

Shouldn’t be that hard to do this, but I can’t get anything I try to work.

Commenting on this Drupal Question is closed.