function pathauto_user in Pathauto 5.2
Same name and namespace in other branches
- 5 pathauto_user.inc \pathauto_user()
- 6.2 pathauto.module \pathauto_user()
- 6 pathauto.module \pathauto_user()
Implementation of hook_user() for users, trackers, and blogs.
File
- ./
pathauto.module, line 360 - Main file for the Pathauto module, which automatically generates aliases for content.
Code
function pathauto_user($op, &$edit, &$user, $category = FALSE) {
switch ($op) {
case 'insert':
case 'update':
_pathauto_include();
// Use the username to automatically create an alias
$pathauto_user = (object) array_merge((array) $user, $edit);
if ($user->name) {
$placeholders = pathauto_get_placeholders('user', $pathauto_user);
$src = 'user/' . $user->uid;
$alias = pathauto_create_alias('user', $op, $placeholders, $src, $user->uid);
if (module_exists('blog')) {
$new_user = drupal_clone($user);
if ($category == 'account') {
$new_user->roles = isset($edit['roles']) ? $edit['roles'] : array();
$new_user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
// Add this back
}
if (user_access('edit own blog', $new_user)) {
$src = 'blog/' . $user->uid;
$alias = pathauto_create_alias('blog', $op, $placeholders, $src, $user->uid);
}
else {
path_set_alias('blog/' . $user->uid);
path_set_alias('blog/' . $user->uid . '/feed');
}
}
if (module_exists('tracker')) {
$src = 'user/' . $user->uid . '/track';
$alias = pathauto_create_alias('tracker', $op, $placeholders, $src, $user->uid);
}
}
break;
case 'delete':
// If the user is deleted, remove the path aliases
$user = (object) $user;
path_set_alias('user/' . $user->uid);
// They may have enabled these modules and/or feeds when the user was created, so let's try to delete all of them
path_set_alias('blog/' . $user->uid);
path_set_alias('blog/' . $user->uid . '/feed');
path_set_alias('user/' . $user->uid . '/track');
path_set_alias('user/' . $user->uid . '/track/feed');
break;
default:
break;
}
}