Hi, I have content_profile for users and registration set up, now I'd like to display some of the values of the fields on every node this user created, is it possible?

firstly wanted to use core profile module, but its not translatable to other languages as CCK fields are

Any piece of code, hint etc would be wonderful, many thanx

Comments

czeky’s picture

it was easy with core profile..

$account = user_load(array('uid'=>$node->uid));
profile_load_profile($account);
print check_plain($account->profile_address);

but with content profile it's little bit hard for me to

thanx

czeky’s picture

found a sort of solution..

$account = user_load(array('uid'=>$node->uid));
$node = content_profile_load('profile', $account->uid); 
print check_plain($node->field_profile_address[0]['value']);

but I need to display this only to allowed roles (cck fields permission enabled), anyone knows how to not to display this field to anonymous user? is there other solution than..?

if (in_array('authenticated user', $user->roles)){
print 'whatever code';
}
dmetzcher’s picture

The Field Permissions module should help you hide this field from certain roles.
http://drupal.org/project/field_permissions

I'm using the following code in a computed field. It is based on your code above. I'm using the Field Permissions module to stop a user from being able to edit their own field_author_bio field (so that site admins can control the look of this field for authors to certain blogs).

$account = user_load(array('uid'=>$node->uid));
$node = content_profile_load('uprofile', $account->uid); 
$author_bio = $node->field_author_bio[0]['value'];
$node_field[0]['value'] = $author_bio;
dmetzcher’s picture

There are issues with the code I used in the CCK field:

$account = user_load(array('uid'=>$node->uid));
$node = content_profile_load('uprofile', $account->uid); 
$author_bio = $node->field_author_bio[0]['value'];
$node_field[0]['value'] = $author_bio;

It's loading the entire profile right into the page where content_profile_load() is used (so wherever that CCK field that contains the code above is present). I'm trying to find a solution now and not having much luck. The comment below might be a solution, but I haven't figured it out yet.

http://drupal.org/node/316009#comment-1221074

strellman’s picture

@ #4 It seems that the conclusion with #33 http://drupal.org/node/316009#comment-1224759 was to presave the profile fields in cache somewhere for that user then access them without loading the node (see comment #35). I am going to try using this to fill in a default for a field in my event_participant node from my content_profile node.
But I don't know PHP, so I may not understand either.

dmetzcher’s picture

I decided to add a field to core profile and simply pull the contents of that field instead of trying to pull the contents of a field on a Content Profile node. My site has several blogs and each blog has several authors. I wanted to include a "mini bio" for each author at the end of their blog posts. Since I'm controlling what is entered into the mini bio field (only admins can see and edit this field), and since the users cannot see it, I don't mind having it be a field in the core profile module. I can make an argument that, for this specific use case, that's where it belongs anyway... or at least that's what I tell myself. ;)