How to Build a Drupal Social Network
Part 2: User Profiles
So! First of all, we're not going to touch drupal's core 'profile' module. You can go ahead and turn that off in your module preferences. Make sure you have Content Construction Kit (CCK), Views and Content Profile enabled before beginning.
Using a node as the user's profile
We're going to use an actual content type, and therefore a node, for the user profile. We're not using drupal's profile module. By using a node, we can do much much more with a user's profile that drupal would typically allow. It also opens up more possibilities for views later down the road.
Limitations of Drupal 6's default profile system
- Field configuration / flexibility: The fields that can be added to drupal's default profile are limited. For example, you can't easily add a croppable profile photo. On top of that, since the fields aren't produced by CCK we won't be able to expose certain fields to certain user groups. If you're building a large social network you'd typically want these features.
- Data retrieval: Because of the way drupal stores data and the way views functions, you'll run into problems trying to aggregate data from profiles merged on other node data. It will be inflexible and bulky to work with.
1. Creating a Profile Content Type
1. Download and Install the Content Profile module: http://drupal.org/project/content_profile
2. Create the new content type: call it "profile"
3. Check "use as profile" in the content type settings.
4. Configure your fields: It's a good idea to make a croppable profile photo, change Title to be "Full Name", etc.
5. Write a redirect for your profile content type to redirect to the user's page. This way you don't have to theme the profile node. This will make more sense later. I usually do my redirects in a contemplate using drupal_goto('user/$node->uid');
6. Generate some dummy accounts and profiles.
Note: Even if your social network requires different profile types, keep it to 1 content type for user profiles and use hidden fields to create the illusion of multiple profile types to your users. It will give you lots of problems later if you use multiple content types for profiles.
2. Theme your "profile"
Now we're ready to generate a nice display for the user profile. I usually do this with views.
1. Blank out the default drupal profile by generating an empty user-profile.tpl.php
2. Create a new view showing items of type node.
3. Add the User: UID argument and select "User ID from URL" as the default argument.
4. Generate a new block display.
5. Use this method to display fields from your content profile, and assign them to the user profile as blocks. I usually make a block for the profile photo, description, etc.
3. Generate a User/Account Bar
Since the profiles are just nodes, you can . . .
1. Make a new node view
2. Use the User: UID argument and select "User UID from logged in user"
3. Select your fields.
4. Add some extra markup for logout and edit profile
4. Generate a listing of all users
1. Again, just use views to do this. I think you can figure it out.
5. Tweak out the registration process.
Personally I absolutely hate Drupal's account activation method where the user has to select their password after activation. If you do too, give loggintoboggan a try.