If I use user_load(), should the fields in content profile be loaded?

I saw in earlier version, the fields were loaded, but that could cause problems (see related post http://drupal.org/node/237691)

Now it appears to me user_load() is no longer loading the content profile fields. Is this the final and correct behavior? Should I assume user_load() will never load the content profile fields? I would like to get a definitive answer so I can update my code accordingly.


#2 content_profile_user_load.patch2.38 KBsdsheridan


Sk8erPeter’s picture

I know this is an old topic, but I just got here.

I think in this case you should return to the stable 6.x-1.0, where user_load() loads all the appropriate Content Profile fields... I think this should be the normal behaviour.

sdsheridan’s picture

new2.38 KB

Agreed. I suspect a number of things depend on this behaviour. I included the following in function_content_profile_user:

/************** PATCH to load profile fields into user object on user_load() call */
case 'load':
$types = "('" . implode("', '", array_keys(content_profile_get_types())) . "')";
$result = db_query("SELECT nid FROM {node} WHERE uid = %d AND type IN $types", $account->uid);
      while (
$nid = db_result($result) ) {
$node = node_load($nid);
        foreach (
$node as $key => $value ) {
          if (
strpos($key, 'field_') === 0 ) {
            if (
count($value) == 1 && isset($value[0]) ) { // single value field
if( count($value[0]) == 1 ) {                 // only one item in the value, so just grab it.
$value_keys = array_keys($value[0]);
$value = $value[0][$value_keys[0]];
              else {                                       
// multiple items in the single value, so preserve the keys
$value = $value[0];
            else {                                         
// more than one value in the field
foreach ( $value as $index => &$item ) {      // so for each item
if ( count($item) == 1 ) {                  // if its got only one attribute
$value_keys = array_keys($item);          // grab just that attribute
$item = $item[$value_keys[0]];
// otherwise the field values cannot
}                                               // be flattened so just leave them be
$account->$key = $value;
/************* End PATCH *******************************************************/

This code will load all content profile fields, and flatten those that can be easily flattened, which preserves behaviour that used to be there before, so other modules I have written wouldn't need to be3 changed.

Would be great to see this get into the next release! I've attached a patch.