I want to develop a module to handle an external db that I want to attach to the drupal site I'm working on. I have extended the user profile to gather info needed for this other db.
I've noticed that unless I call user_load myself, I am not able to access this extended information with $user->my_extended_field_name. Wondering why this is so, I've been looking at the login process. Now, it is my understanding that $user, to be accessed/changed or whatever in a function must be declared as global as in the following php snippet.
<?php
global $user;
if ($user->uid) {
print('Current user uid is '.$user->uid);
}
?>
I've tracked the login process and cannot find where user_load is called in such a way that actually updates the global $user object.
I'm struggling a bit here as I'm not really conversant with how drupal hangs together. Have I missed something or am I right?
Any help would be greatly appreciated.
Comments
As an addendum, user_login
As an addendum, user_login calls user_module_invoke with the $type parameter set to 'login'. This invokes profile_user which is not set up for the case 'login' and so does nothing. It would be nice, at least for my purposes, if 'login' did the same as 'load' in this function.
edit: I think I'm barking up the wrong tree here. As drupal moves from page to page or whatever, I guess user_load gets called where needed. This calls profile_load_profile which is what I'm after.
It would be useless calling it once, say at login. I get caught up in the code and forget it's all working through a browser so these things disappear when the browser changes state!
My apologies. This thread has become my own 'thinking out loud'.
disclaimer - I am not an
disclaimer - I am not an expert!!!
I think what you are looking for is in sess_read() in the session.inc file. This basically reads the everything from the user table into the $user global var (it uses the drupal sessions table to 'remeber' that you have logged on etc).
I've not played with the profile module so i could be talking absolute nonsense and this might not be any help at all ;)
A good thing to do (and i think i've seen it recommended on here before) is to use the debug tools in something like Komodo (http://www.activestate.com/Products/Komodo/) to step through the executing of drupal - should help you figure out whats going on where ...
Mike,
Computerminds offer Drupal development, consulting and training