Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, urls that use the url_alias table do not allow arguments. This is not desirable because it is useful to be able to specify arguments on a script that is aliased without having to refer to it by node number.
The code below replaces the drupal_get_normal_path() function in common.inc to allow aliased paths to have arguments.
/**
* Given a path alias, return the internal path it represents.
*/
function drupal_get_normal_path($path) {
if (($map = drupal_get_path_map()) && isset($map[$path])) {
return $map[$path];
}
elseif (function_exists('conf_url_rewrite')) {
return conf_url_rewrite($path, 'incoming');
}
else {
//look at each of the path components of $path and allow extra components to be arguments
//do a greedy search first for the largest paths
if ($map && (strpos($path, '/') !== false)) {
$newpath = clone($path);
$args = '';
while($path_end = strrpos($newpath, '/')) {
$args = substr($newpath, $path_end).$args;
$newpath = substr($newpath, 0, $path_end);
//check to see if this new path exists in the path map
if(isset($map[$newpath])) {
return $map[$newpath].$args;
}
}
}
//no alias was found, return the original path
return $path;
}
}
Comments
Comment #1
Steven CreditAttribution: Steven commentedFirst, I'm not sure if this is desirable. Without at least some examples it is hard to tell.
However, it seems to me that without similar changes in the path-to-alias conversion, we get very inconsistent path handling. I imagine you want to create links to argumented aliases yourself, but Drupal would only output identical aliases. This goes against the idea that URLs should be unique identifiers as much as possible.
Also please submit proper patches in unified diff format. Otherwise it is very hard to see what has changed. Take a look at Drupal's coding conventions too. And why are you calling clone() on a string? Strings are passed and assigned by value.
Comment #2
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedIt's a feature request, there is not patch, and new features go into cvs only.
Comment #3
ricabrantes CreditAttribution: ricabrantes commentedThis is active??
Comment #4
marcingy CreditAttribution: marcingy commentedBumping version
Comment #5
Dave ReidComment #6
Dave ReidIt's hard at all to tell what's going on here since core's changed so much. Please re-open with a re-clarification or search to see if someone has reported something similar.