You are here

function pathauto_user in Pathauto 5

Same name and namespace in other branches
  1. 5.2 pathauto.module \pathauto_user()
  2. 6.2 pathauto.module \pathauto_user()
  3. 6 pathauto.module \pathauto_user()

Implementation of hook_user() for users, trackers, and blogs

File

./pathauto_user.inc, line 77

Code

function pathauto_user($op, &$edit, &$user, $category = FALSE) {
  switch ($op) {
    case 'insert':
    case 'update':

      /*
       ** Use the username to automatically create an alias
       */
      if ($edit['name']) {
        $placeholders = array();
        $placeholders[t('[user]')] = pathauto_cleanstring($edit['name']);
        $placeholders[t('[uid]')] = $user->uid;
        $src = 'user/' . $user->uid;
        $alias = pathauto_create_alias('user', $op, $placeholders, $src);
        if (module_exists('blog')) {
          $src = 'blog/' . $user->uid;
          $alias = pathauto_create_alias('blog', $op, $placeholders, $src);
        }
        if (module_exists('tracker')) {
          $src = 'user/' . $user->uid . '/track';
          $alias = pathauto_create_alias('tracker', $op, $placeholders, $src);
        }
      }
      break;
    case 'delete':

      /*
       ** If the user is deleted, remove the path aliases
       **
       */
      $user = (object) $user;
      path_set_alias('user/' . $user->uid);
      if (module_exists('blog')) {
        path_set_alias('blog/' . $user->uid);
      }
      if (module_exists('tracker')) {
        path_set_alias('user/' . $user->uid . '/track');
      }
      break;
    default:
      break;
  }
}