function pathauto_user in Pathauto 6
Same name and namespace in other branches
- 5.2 pathauto.module \pathauto_user()
- 5 pathauto_user.inc \pathauto_user()
- 6.2 pathauto.module \pathauto_user()
Implements hook_user().
1 string reference to 'pathauto_user'
- _pathauto_include in ./
pathauto.module - Include all Pathauto include files.
File
- ./
pathauto.module, line 531 - Main file for the Pathauto module, which automatically generates aliases for content.
Code
function pathauto_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
case 'insert':
case 'update':
// Build the user object.
$pathauto_user = (object) array_merge((array) $user, $edit);
// Skip processing if the user has disabled pathauto for the account.
if (isset($pathauto_user->pathauto_perform_alias) && empty($pathauto_user->pathauto_perform_alias)) {
return;
}
// Use the username to automatically create an alias
_pathauto_include();
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 (node_access('create', '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);
}
if (module_exists('contact')) {
$src = 'user/' . $user->uid . '/contact';
$alias = pathauto_create_alias('contact', $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');
path_set_alias('user/' . $user->uid . '/contact');
break;
}
}