function path_alias_xt_get_path_alias in Extended Path Aliases 7
Same name and namespace in other branches
- 6 path_alias_xt.module \path_alias_xt_get_path_alias()
Override the call drupal_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, so this function needs to be invoked via a call inserted in function drupal_get_path_alias() or by using the PECL runkit. Both options are described in detail in the README file.
@todo simplify this code w.r.t 'user' exceptions
Parameters
string $path: If omitted the current path is used.
string $path_language: The path language.
Return value
string The alias for $path or $path unchanged if no alias was found.
File
- ./
path_alias_xt.module, line 180 - Extended Path Aliases.
Code
function path_alias_xt_get_path_alias($path = NULL, $path_language = NULL) {
if ($path == NULL) {
$path = $_GET['q'];
}
// First test for special case user/%.
global $user;
$user_special = variable_get('path_alias_xt_user_special', TRUE);
if ($user_special && preg_match('{^user/([0-9]+)\\z}', $path, $matches) && $matches[1] == $user->uid) {
// For current 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 'node' or 'user' or 'taxonomy/term'
// $matches[2] will be the node, user or term id, e.g '123'
// $matches[3] is the path extension, e.g., 'edit'.
if ($user_special && $matches[1] == 'user' && $matches[2] == $user->uid) {
// For current user rather than applying 'user/%' alias, apply
// '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;
}