Is there a way to auto-populate CCK fields during node creation using a users stored values in Content Profile as in the example below using core Profile module?
I used the following in the default value PHP code to fetch a user's name using core Profile module:
global $user;
if ($user->uid) {
profile_load_profile($user);
return array(
0 => array('value' => $user->profile_name),
);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | job_seeker__content_profile.PNG | 34.84 KB | clashar |
Comments
Comment #1
realityloop commentedI figured this out :)
Comment #2
clashar commentedrealityloop,
I would like to do the same thing.
I changed your code to correspond to my names, but it doesn't work. Maybe I did some wrong changes, could you please see:
I changed :
"profile" to "jobseeker_profile", this is the machine name of my content profile.
"field_owneroperator" to "field_profile_first_name", this is the CCK field in "jobseeker_profile".
is it ok?
Comment #3
realityloop commentedclashar: I'm guessing you need to use the following:
Content types are usually hyphenated not underscored..
Comment #4
clashar commentedrealityloop,
on my settings for content type it's underscored, please see screenshot.
Comment #5
clashar commentedI've tried hyphen, but with no success
Comment #6
realityloop commentedHave you checked the 'content profile' option on the Jobseeker Profile content type's edit page?
Comment #7
clashar commentedyes of course, it works as content profile and I have fields on user profile form
Comment #8
realityloop commentedI'd suggest outputting the field in question using dpm() and the devel module, it may possibly store it's information differently.
Comment #9
clashar commentedwhen I print in dev "Execute PHP Code" script like that:
or
it gives me a value with no problem.
Seems that my problem is related to the use of this code in node reference field.
Comment #10
clashar commentedI opened a new issue related to node reference #935856: can't get result from "PHP code" in "Default value" section.
Comment #12
sean_a commentedI did this and it works. It populated the cck field with the content profile of the logged in user. There was another thread http://drupal.org/node/233378 that helped me figure out how to structure the returned array.
$authorref - made up variable just for this function
profile - content type name
This assumes the current logged in user has a profile, if not the field is left blank.
For migration purposes, It'd be nice have it set to the profile of the author of the node rather than the logged in user but I'm not sure how to do that.
Comment #13
socialnicheguru commentedI have a profile that is a content profile and I allow a person to create several professional experiences.
I have a node reference field_reference_professional. It is unlimited
I return a subset a subset of only the professional experiences that the author has created.
I would like to now set field_reference_professional to all of those by default.
Any idea?
Comment #14
socialnicheguru commentedI wrote this to just return one value and am still getting an error:
global $user;
$myprofile_interests = content_profile_load('my_profile_interest', $user->uid);
if ($myprofile_interests !=NULL) {
return array(
0 => array('nid' => $myprofile_interests->nid),
);
}
I get this: