function pathauto_user in Pathauto 6.2
Same name and namespace in other branches
- 5.2 pathauto.module \pathauto_user()
- 5 pathauto_user.inc \pathauto_user()
- 6 pathauto.module \pathauto_user()
Implements hook_user().
File
- ./
pathauto.module, line 661 - Main file for the Pathauto module, which automatically generates aliases for content.
Code
function pathauto_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'insert':
// When hook_user('insert') is run, most of the account object has been
// saved into $account, except for $account->data and $account->roles.
// Since tokens may depend on the user's data or permissions, we need to
// ensure we have a 'full' user object.
$merged_account = drupal_clone($account);
// Merge in account data.
$merged_account->data = array();
$user_fields = user_fields();
foreach ($edit as $key => $value) {
if (substr($key, 0, 4) !== 'auth' && $key != 'roles' && !in_array($key, $user_fields) && $value !== NULL) {
$merged_account->data[$key] = $value;
}
}
// Merge in user roles.
if (isset($edit['roles']) && is_array($edit['roles'])) {
$roles = user_roles();
foreach (array_keys($edit['roles']) as $rid) {
if (!isset($merged_account->roles[$rid])) {
$merged_account->roles[$rid] = $roles[$rid];
}
}
}
pathauto_user_update_alias($merged_account, 'insert');
break;
case 'after_update':
pathauto_user_update_alias($account, 'update');
break;
case 'delete':
// If the user is deleted, remove the path aliases
pathauto_path_delete_all("user/{$account->uid}");
pathauto_path_delete_all("blog/{$account->uid}");
break;
}
}