function path_alias_xt_get_path_alias in Extended Path Aliases 6
Same name and namespace in other branches
- 7 path_alias_xt.module \path_alias_xt_get_path_alias()
This is used to override the call drupal_get_path_alias(), which occurs for instance in the block.module. There is no hook available for this.
_language
Parameters
$path:
Return value
string The alias for $path or $path if no alias was found.
File
- ./
path_alias_xt.module, line 86 - Extended Path Aliases.
Code
function path_alias_xt_get_path_alias($path, $path_language = '') {
global $user;
if (preg_match('{^user/([0-9]+)\\z}', $path, $matches) && $matches[1] == $user->uid) {
// For logged-in user rather than applying 'user/%' alias, return 'user'
// alias, if it exists.
if ($user_alias = drupal_lookup_path('alias', 'user', $path_language)) {
return $user_alias;
}
}
if ($alias = drupal_lookup_path('alias', $path, $path_language)) {
return $alias;
}
$pattern = variable_get('path_alias_xt_regex_pattern', PATH_ALIAS_XT_DEFAULT_NODE_OR_USER_MATCH);
if (preg_match($pattern, $path, $matches)) {
// $matches[0] equals $path, eg 'node/123/edit'
// $matches[1] will equal either 'node' or 'user'
// $matches[2] will be either the node or user id, e.g '123'
// $matches[3] is the path extension, e.g. 'edit'
if ($matches[1] == 'user' && $matches[2] == $user->uid) {
// For logged-in user rather than applying 'user/%' alias, return 'user'
// alias, if it exists.
if ($user_alias = drupal_lookup_path('alias', 'user', $path_language)) {
return "{$user_alias}/{$matches[3]}";
}
}
if ($alias = drupal_lookup_path('alias', "{$matches[1]}/{$matches[2]}", $path_language)) {
return "{$alias}/{$matches[3]}";
}
}
return $path;
}