Closed (works as designed)
Project:
User Import Framework
Version:
7.x-1.0-beta5
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
1 Feb 2011 at 10:14 UTC
Updated:
1 Jun 2012 at 20:12 UTC
Jump to comment: Most recent file
Comments
Comment #1
dwightaspinwall commentedHi - the example on the project page is for drupal 6, using the optional Profile module which is part of core. The Profile module has been deprecated in drupal 7, since you can add fields to users. Or optionally, you could look at Profile2 module, which is the Drupal 7 successor to Profile - http://drupal.org/project/profile2
Regardless of which approach you take the idea should be the same. You're going to use hook_uif_pre_create() to assign data into the field. The trick is to find out the name of the variable in the user object. And for that I suggest the Devel module, which puts a tab on user/ which shows a dump of the user object. So, just add the fields, populate a user with some data via the UI, then use user//devel to find out the variable naming convention. Then use that convention in your hook.
Comment #2
alarfaj commentedThank you,
I used something like this and it worked.
$lang = LANGUAGE_NONE;
$profile['field_fname'][$lang][0]['value'] = $user_data['fname'];
Comment #3
dwightaspinwall commentedCool. Glad you got it working.
Comment #4
dan3h commentedThe solution above didn't work for me -- I think it is for drupal 6, or for the old (deprecated) profiles module which it is still possible to use in drupal 7. I am using the Profile2 module, and it has a different API.
Here is what worked for me with Profile2. I'm leaving out the code which imports the normal user fields (username, password, etc... anything that resides in the 'users' table) -- that part works already, as per the code example that comes with the
uif_example.module. My code here is the part that deals with profile2 fields. It seems that first, you have to create the user objects, and then you can add the profile2 field values. That's why I'm using the hook_uif_post_* functions:Comment #5
bensnyder commentedthanks @dan3h your code helped me do a successful mapping/import
Comment #6
dwightaspinwall commentedGlad we got resolution on this. Added note to project page doc.
Comment #7
shadowdknight commentedHi
Can anyone provide with full piece of code please,
Im confuse , where should I add the working piece.
For example my profile 2 machine name is : main
additional field is: field_phone
Thanks!
Comment #8
bensnyder commented@shadowhitman #7
Here's the full code that worked for me; it's a custom module. It's still got the field names I used- so you need to change it to fit your needs.
Comment #9
bensnyder commentedOH! Take note!
I added
realname_update($account);Which requires the realname module. You need to either remove that code (I think I added it twice in the .module) or have realname.module set up and ready.
Good luck
Comment #10
shadowdknight commentedIt works!!!
Thanks you so much!
Comment #11
wooody commentedThanks , works with me
Comment #12
funkeyrandy commentedvery cool. How about assigning multiple roles from the csv import? mine are "|" separated: admin|subscriber| etc
Comment #13
dwightaspinwall commentedEasily done in a hook_uif_post_create and/or hook_uif_post_update funkeyrandy. Just update the user and call user_save(). Hope that helps.
Next time, please open a new issue, since your comment was unrelated. Thanks.
Comment #14
funkeyrandy commentedin drupal 7, what would be the best way to get regular profile fields?
is the standard profile saved along with user_save ? it seems it must be different than:
$profile->field_profile_fname[LANGUAGE_NONE][0]['value'] = $user_data['fname'];
i thought this would do it:
thanks!
Comment #15
funkeyrandy commentednevermind...figured it out with:
$account->field_phone[LANGUAGE_NONE][0]['value'] = $phone;
Comment #16
dwightaspinwall commentedBen,
Thanks for the module in http://drupal.org/node/1047266#comment-5308174 Inspired me to add a new example module to the project to show profile 2 support. Going into dev today, and will be in 7.x-1.1 and later.
Comment #17
bensnyder commented@dwightaspinwall - Glad to be of service and thank YOU for all the work YOU'VE done.