function path_alias_xt_url_inbound_alter in Extended Path Aliases 7
Implements hook_url_inbound_alter().
File
- ./
path_alias_xt.module, line 75 - Extended Path Aliases.
Code
function path_alias_xt_url_inbound_alter(&$path, $original_path, $path_language) {
// While drupal_get_path_alias() can't be overridden, drupal_get_normal_path()
// does let us augment its behaviour by implementing this hook.
// The system path as calculated and passed to us by drupal_get_normal_path(),
// when no alternative system path was found by that function, we apply our
// algorithm to create an system (aka normal) path.
// @see includes/path.inc
// Remove whatever alterations PURL has done to determine the actual path.
if (module_exists('purl') && purl_inited()) {
$original_path = purl_get_normal_path($path);
}
if (!empty($original_path) && $path == $original_path) {
// drupal_get_normal_path() did not find a system path.
// See [#2162621]. This deals with special UTF characters in paths.
// @todo: make this should be configurable?
$candidate_alias = $original_path;
// This needs to use explode() and not strrpos() / drupal_substr(), because
// strrpos() is not unicode safe, so unicode characters can lead to an
// endless loop.
$parts = explode('/', $candidate_alias);
$path_suffix = array();
while (count($parts) > 0) {
// If the truncated path exists as a menu item (incl. paged views), abort.
// E.g.: we won't replace and extend the user alias 'admin' in this path:
// admin/structure/block/manage/system/navigation/configure, because
// admin/structure/block is in the menu-router table.
if ($menu_item_path = _path_alias_xt_get_menu_item($candidate_alias)) {
return;
}
array_unshift($path_suffix, array_pop($parts));
$candidate_alias = implode('/', $parts);
if ($src = drupal_lookup_path('source', $candidate_alias, $path_language)) {
// If 'user' is aliased to MyAccount, then MyAccount/edit needs to
// transform to 'user/123/edit'.
if ($src == 'user') {
global $user;
$src .= '/' . $user->uid;
}
$path = $src . '/' . implode('/', $path_suffix);
return;
}
}
}
}