function custom_url_rewrite_inbound in Extended Path Aliases 6
Implementation of pseudo-hook custom_url_rewrite_inbound().
Because we modify drupal_get_path_alias(), we also have to implement the complimentary action in drupal_get_normal_path(). Fortunately, while drupal_get_path_alias() can't be overridden, drupal_get_normal_path() does let us override its behaviour by implementing custom_url_rewrite_inbound().
Parameters
$result: The internal path as calculated and passed to us by drupal_get_normal_path(). When no alternative internal path was found by that function, we apply our algorithm to create an internal (aka normal) path.
$path: The original path or its alias.
$path_language:
See also
includes/path.inc
File
- ./
path_alias_xt.module, line 137 - Extended Path Aliases.
Code
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
if (!empty($path) && $result == $path) {
// drupal_get_normal_path() did not find an alias
// If the path exists as a menu item (incl. paged views), abort.
if (_path_alias_xt_get_menu_item($path)) {
return;
}
$candidate_alias = $path;
while ($pos = strrpos($candidate_alias, '/')) {
$candidate_alias = substr($candidate_alias, 0, $pos);
if ($src = drupal_lookup_path('source', $candidate_alias, $path_language)) {
if ($src == 'user') {
global $user;
// Insert uid into path
$src .= '/' . $user->uid;
}
$result = $src . substr($path, $pos);
return;
}
}
}
}