I am using ‘Content Profile’ module. I have a CCK text field ‘Full Name’ from profile content type, which I am using as ‘realname’.

I have a block ‘New users’ having user list, placed in right sidebar. When I create a user via ‘Add user’ page [http://localhost/drupal/admin/user/user/create], ‘New Users’ blocks shows number instead of real name. [see user_list.jpg]

I did some research on it and came to know that user account is first created and then its content profile.
In ‘Realname’ module, ‘hook_user’ function makes call to ‘_realname_make_name’ helper function which loads the content profile of user. But at this point, corresponding content profile node is not created. In this case ‘User name’ is used as realname i.e. number (created timestamp). Due to which this issue occurs. Due to this, user id is not associated to node (content profile node), when user is created via ‘Add user’.

Further, in custom module, the $node object received in ‘hook_nodeapi’, has user id (i.e. ‘uid’ property) 0 when user created via ‘Add user’ page. But when user is created through ‘User Registration’ page, proper user id is present in user profile node object.

Proposed solution –
I have used below approach to associate user to its node profile at the time of user creation.
Below changes are made in custom_module.module file on local setup.

1. In hook_user, save ‘user id’ in session variable when operation is ‘insert’

/**
* Implementation of hook_user().
*/
function custom_module_user($op, &$edit, &$account, $category = NULL) {  
  if ($op == 'load') {
  // Replace account name by realname, if realname exist.
    if ($account->realname) {
      $account->name = $account->realname;
    } 
  }
  else if($op == 'insert') {  
     $_SESSION['registered_user_id'] = $account->uid;
  }
}

2. In hook_nodeapi, assign user id stored in session variable to node objects user id and then unset session variable.

/**
* Implementation of hook_nodeapi() 
*/ 
function custom_module_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   
    if ($node->type == 'profile' && ($op == 'insert' ||  $op == 'update') && module_exists('realname')) {
        if(  ($node->uid == 0)
          && isset($_SESSION['registered_user_id']) 
          && ($op == 'insert')
        ) {
          $node->uid = $_SESSION['registered_user_id'];
          unset($_SESSION['registered_user_id']);
          node_save($node);
        }
    } 
}

I am still working on this approach but as of now it appeared to be working fine.
Can anyone let me know the best approach to resolve the above issue? Thanks in advance.

CommentFileSizeAuthor
#1 user_list.JPG7.78 KBnileema19

Comments

nileema19’s picture

StatusFileSize
new7.78 KB

screenshot -

hass’s picture

Status: Active » Closed (outdated)