This is really basic and stupid, and I have searched the site for an answer but can't find one.

I'm just trying to create a menu item:

Home › Administer › Site building › Menus

The form prompts for Title, Description, Path, Parent item, etc.

In the path I want to specify a URL that has query arguments:

view/ticketselector?sort=asc&order=Priority&op0=OR&op1=OR&filter1[0]=6&filter1[1]=7&op2=AND&op3=OR

It is a custom view of my cases from casetracker. Well the URL gets encoded so it doesn't work:

view/ticketselector%3Fsort%3Dasc%2526order%3DPriority%2526op0%3DOR%2526op1%3DOR%2526filter1%5B0%5D%3D6%2526filter1%5B1%5D%3D7%2526op2%3DAND%2526op3%3DOR

How do I tell drupal to not url encode the thing? This seems like a basic thing to want to do. . .

Thanks,

-Bob

Comments

hsfdrupal’s picture

Anyone?

piersg’s picture

commenting out a line in common.inc (line with XX in)

 // The special path '<front>' links to the default front page.
  if (!empty($path) && $path != '<front>') {
    $path = drupal_get_path_alias($path);
 //XX   $path = drupal_urlencode($path);
    if (!$clean_url) {

although I'm not sure of the side-effects of this. I guess it should be done properly with the $query variable but I can't get my head round it just now.

I want to get it working because I want a link that logs a user in and goes to a particular page (I know there is a module for this...) and I want a primary link like "Log On To Members' Area" with a url like user/login?destination=members, which does this nicely

jadowd’s picture

Set your 404 page to a node that you create in php format. I use an include file from disk to set up a notification system which sends me an email for any site called resource (meaning, if it comes from outside the site, I don't care about it). To account for the fact that I want to catch url arguments correctly, I use the following code:

  if(preg_match('/&/', $uri || '/?/', $uri || '/=/', $uri)){
    echo($uri);
    echo('<br>URI has char &<br>');

    $uri = str_replace('&', '%2526',$uri);
    $uri = str_replace('=', '%3D',$uri);
    $uri = str_replace('?', '%3F',$uri);

    $redir = $server.$uri;
    header("Location: http://$redir");
    return;
  }

This only covers the characters =, ? and &. I haven't had need for any others, but it works.

andriy’s picture

you can do it by inserting the following function to your templates.php file in the your theme directory:

function phptemplate_menu_item_link($item, $link_item) {
$url = parse_url($link_item['path']);

// if our path has a query , move this query from $link_item['path'] to $item['query'], so l() function can append it properly
if (isset($url['query'])) {
$link_item['path'] = str_replace('?' . $url['query'], '', $link_item['path']);
$item['query'] = $url['query'];
}

return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}

this will correctly display query arguments for every menu item, but keep in mind that parse_url is performed on each menu item, and it can be very expensive, so consider to place some condition matching your case, something like:

function phptemplate_menu_item_link($item, $link_item) {
if (strstr($link_item['path'], 'view/ticketselector?')) {
$url = parse_url($link_item['path']);
if (isset($url['query'])) {
$link_item['path'] = str_replace('?' . $url['query'], '', $link_item['path']);
$item['query'] = $url['query'];
}
}

return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}

hope, it helped

arthurf’s picture

I think it might be a bit easier to do it like this-

<?php
/**
 * Custom menu link function that supports queries
 * @param $item
 * @param $link_item
 * @return unknown_type
 */
function THEME_menu_item_link($item, $link_item) {
  // do we need to parse this item?
  if (strstr($link_item['path'], '%3F')) {
    // decode the URL
    $item['query'] = urldecode($link_item['path']);
    // get the path and query from the URL
    $path = explode('?', $item['query']);
    $link_item['path'] = $path[0];
    $item['query'] = $path[1];
  }
  return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}
?>
arthurf’s picture

The above code handles encoded links, this handles non-encoded (eg: path/mine?argument=blah)

<?php
/**
 * Custom menu link function that supports queries
 * @param $item
 * @param $link_item
 * @return unknown_type
 */
function THEME_menu_item_link($item, $link_item) {
  // do we need to parse this item?
  if (strstr($link_item['path'], '?')) {
    // get the path and query from the URL
    $path = explode('?', $link_item['path']);
    $link_item['path'] = $path[0];
    $item['query'] = $path[1];
  }
  return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}

?>