Social Networks and Extending the User Profile in Drupal: Part-2

Exclusive offer: get 50% off this eBook here
Drupal for Education and E-Learning

Drupal for Education and E-Learning — Save 50%

Teaching and learning in the classroom using the Drupal CMS

$26.99    $13.50
by Bill Fitzgerald | November 2009 | Drupal Open Source

Read Part One of Social Networks and Extending the User Profile in Drupal here.

Building the Profile

The Content Profile module creates a new content type called Profile when it is enabled. By default, this content type is set to be used as a profile. We need to complete a few additional steps to make our profile fully functional.

  1. Edit the default settings for the Profile content type
  2. Configure the base Content Profile settings
  3. Add any required fields to the Profile content type
  4. Add any taxonomy terms to the Profile content type
  5. Assign rights to create and edit the Profile content type

Edit the Settings of the Profile Content Type

As mentioned above, when the Content Profile module is enabled, it creates a new content type named Profile. To use this new node type effectively, we need to change the default settings.

To do this, click on the Administer | Site building | Content types link, or navigate to admin/content/types. Click the Edit link for the Profile content type.

The Automatic Nodetitles module—enabled earlier in the first part of  this article—adds a new fieldset labeled Automatic title generation at the top of the administrative screens where we edit content types.

Social Networks and Extending the User Profile in Drupal

As shown in the preceding screenshot, we have two options. For the first option, we want to select Automatically generate the title and hide the title field.

For the second option—Pattern for the title—we should enter [author-name]'s profile. [author-name] is a token; when the node is created, the token will be replaced by the username of the person creating the node. So, if a user named Jill created the profile node, the title would be Jill's profile.

The Token module allows us to use a wide range of tokens in addition to [author-name]. To see the full list of available tokens, expand the Replacement patterns fieldset as indicated in the preceding screenshot by Item 1.

The settings listed here also need to be adjusted:

  • In the Submission form settings section, delete the Body field label. We do not want this node type to have a body field; we will add all needed fields using CCK
  • In the Workflow settings section, set the Default options to Published, and Attachments to Disabled
  • In the Comment settings section, set the Default comment settings to Disabled

After you have made the necessary adjustments, click the Save content type button to submit the form and save your changes.

Configure the Base Content Profile Settings

To configure the base Content Profile settings, click on the Administer  Site building | Content types link, or navigate to admin/content/types. Click the Edit link for the Profile content type. Then, click the Content Profile tab.

Social Networks and Extending the User Profile in Drupal

The base settings allow us to configure how the node profile will be displayed on the user profile page. As shown in the preceding screenshot, in the User page display style section we have four options:

  • Don't display this content profile on the user account page—only select this option if you will be overriding the core user profile page via the theming layer. This is an advanced theming technique; refer to the handbook page on overriding user profiles at http://drupal.org/node/35728.
  • Display it as link to the profile content—select this option if you only want to link to the full profile node from the user profile page.
  • Display the full content—this option displays the full node on the user profile page.
  • Display the content's teaser—this option displays the teaser view on the profile page. As discussed later in this section, this option provides us some flexibility not found in the other options. For our example, choose this option.

The final two options—Include an edit link to the display and Show a link to the content profile creation page, if there is no profile—should both be selected, as they improve usability.

The Weight can be left at 0.

When these settings have been adjusted as needed, click the Submit button to save the changes.

Add Fields to the Profile Content Type

Now that we have edited the defaults of the Profile node type, and adjusted the base settings of the Content Profile, we are ready to add fields and taxonomy terms to our profile. The CCK fields and Taxonomies will provide structure to our user profiles.

For this example, we want to extend our profile by adding two fields, and one vocabulary.

The fields we will add will both be text fields; one for a Brief bio, and the second for a Full bio.

We will also add a Vocabulary to the Profile content type called Interests. Adding this vocabulary is covered in the next section of this article.

Add the Brief Bio Field

To add the text fields, go to the Content Types administration page by clicking the Administer | Content Management | Content Types link, or by navigating to admin/content/types. Click the manage fields link for the profile content type.

In the Add section, we want to add a New field. Enter the following values:

  • Label: Brief bio
  • Field name: brief_bio
  • Field type: text
  • Widget type: text area (multiple rows)

Click the Save button; this brings up the admin screen where you can configure the field.

Social Networks and Extending the User Profile in Drupal

As shown in the preceding screenshot, the form to configure the text field has two sections: Profile settings and Global settings.

Adjusting the Profile Settings

In the Profile settings, we have two options; enter the values specified below:

  • Rows: 3
  • Help text: Enter your brief bio. 500 characters maximum

For this example, we do not need to set any Default value.

Adjusting the Global Settings

In the Global settings, we have four options; enter the values specified below:

  • Required: No; leave unchecked
  • Number of values: 1
  • Text processing: Plain text
  • Maximum length: 500

For this example, we do not need to set any Allowed values.

Once the field has been configured as needed, click the Save field settings button to save your changes.

Adding the Full Bio Field

Adding the Full Bio is nearly identical to adding the Brief bio. When adding the field, use the following values:

  • Label: Full bio
  • Field name: full_bio
  • Field type: text
  • Widget type: text area (multiple rows)

Click the Save button; this brings up the admin screen where you can configure the field.

In the Profile settings, enter:

  • Rows: 5
  • Help text: Enter your full, extended biography.

In the Global settings, we enter:

  • Required: No; leave unchecked
  • Number of values: 1
  • Text processing: Filtered text (user selects input format)
  • Maximum length: none, leave blank

Once the field has been configured as needed, click the Save field settings button to save your changes.

Adjusting the Field Display

As we discussed above when we configured the base options for Content Profiles, we want to show the node teaser on the user profile page. To take advantage of this option, we need to configure how we display our fields. To do this, go to the Content Types administration page by clicking the Administer | Content Management | Content Types link, or by navigating to admin/content/types. Click the edit link for the profile content type, and then, click the Display fields tab.

Social Networks and Extending the User Profile in Drupal

As seen in the preceding screenshot, you can control how fields are displayed in the Teaser view and in the Full node view.

In the settings shown in the preceding screenshot, we have set the Brief bio to show on the Teaser view (that is, on the user profile page), and the Full bio to display on the Full node view (that is, when the entire profile is being viewed). Our settings display a truncated overview on the user profile page, with a link to the more detailed full node view.

Add Taxonomy Terms to the Profile Content Type

As described above, we want to add an Interests vocabulary.

To add new vocabularies, click on the Administer | Content management | Taxonomy| link, or navigate to admin/content/taxonomy. Click the Add vocabulary tab.

Adding the Interest Vocabulary

For Interests, enter the following values:

  • Vocabulary name: Interests
  • Description: none, leave blank
  • Help text: Describe your interests. Separate each interest with a comma
  • Content types: select Profile; leave others unchecked
  • Settings: select Tags; leave others unchecked
  • Weight: -6

Click the Save button to create the new vocabulary.

Assign Rights to Profile Nodes

Click on the Administer  User Management | Roles| link, or navigate to admin/user/roles. Select the role(s) that you would like to be able to create node-based profiles. Generally, users should be given the rights to create profile content, and edit own profile content. This will allow users to create their own profiles, and update them as needed, but also protects users from accidentally deleting their profile.

Only site administrators or especially trusted users should be given the rights to edit any profile content or delete any profile content.

Drupal for Education and E-Learning Teaching and learning in the classroom using the Drupal CMS
Published: November 2008
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

Creating an Extended Profile

Now that we have made all of the necessary adjustments to the Profile content type and the Content Profile settings, we are ready to have users populate their profiles.

Users can fill out their profiles by navigating to their profile page, either by clicking on the My Account link or by navigating to http://example.edu/user when they are logged in. If a user has not completed their profile, they will be presented with a link to complete it.

Social Networks and Extending the User Profile in Drupal

This screenshot is taken from the perspective of the profile owner; that is, this profile is owned by user helen, and this screenshot was taken while the user was logged in as helen.

As shown in the preceding screenshot, the Last name and Birthday fields we created earlier in this article are visible. The Create your Profile link is displayed because the user helen has yet to complete her profile. Clicking the Create your Profile link allows us to fill in the form.

Social Networks and Extending the User Profile in Drupal

As shown in the preceding screenshot, our profile contains textareas for the Brief and Full bio, as well as a vocabulary for Interests. Additionally, the Title field on the form is hidden, as we specified via the Automatic Nodetitles settings.

When you have entered the appropriate values, click the Save button to create the extended profile.

Including Fields from the Profile Node on the Registration Form

If you would like to include any of the fields from the node-based profile on the user registration form, you will need to enable the Content Profile User Registration module. As mentioned earlier in this article, this module ships with the Content Profile module; like all modules, it can be enabled at Administer | Site building | Modules, or admin/build/modules.

Once the module has been enabled, we will need to access the base Content Profile settings by clicking on the Administer  Site building | Content  types link, or by navigating to admin/content/types. Click the Edit link for the Profile content type, and then, click the Content Profile tab.

Social Networks and Extending the User Profile in Drupal

The Content Profile User Registration module adds the User Registration fieldset. To compare this form before Content Profile User Registration has been enabled, see the Profile screenshot earlier in this article under the section Configure the Base Content Profile Settings.

To show fields on the new user registration form, select the Use on Registration option, and then select all the fields that you DO NOT want to show on the form.

The default is to show fields on the form.

Once you have configured the settings to your desired specifications, click the Submit button to save these settings.

Additional Options for Social Networking and User Profiles

In many social networking sites, people often want to allow users to "become friends" with one another. Although the advisability of this type of interaction in a classroom setting is a matter of much debate, this functionality can be delivered through two different modules: User Relationships and Friendslist, available at http://drupal.org/project/user_relationships and http://drupal.org/project/friendlist, respectively. These two modules achieve similar goals, and it is not inconceivable that, over time, one of these modules will supersede the other. As of this writing, however, both modules are actively supported.

Another module that is worth checking is the Advanced Profile Kit, available at http://drupal.org/project/advanced_profile. This module provides a set of tools for building and theming complex user profiles.

Additionally, if you want to work directly with the theming layer, the possibilities for user profiles are virtually limitless. Additionally, you can find excellent information in the theming section of the Drupal handbook at http://drupal.org/theme-guide and the handbook page on overriding user profiles at http://drupal.org/node/35728.

Summary

In this article, we looked at how to build user profiles using the core Profile module, and then how to extent the user profile using the Content Profile module. The best solution for you will certainly be determined by the goals that you want to achieve in your site.

A well-constructed user profile allows people to express areas of personal interest and learn details about other site members. While this is not necessary in all class settings, in contexts where this is appropriate, a detailed user profile can provide a starting point for site members to have more personal investment in the site.

The techniques covered in this article allow you to build effective user profiles that address a broad range of needs. Through judicious use of the theming layer, or by using other contributed modules shared on Drupal.org, more can be done with user profiles. In short, building an effective user profile allows your users to have some fun, and learn about one another in the process.

[ 1 | 2 ]

If you have read this article you may be interested to view :

 

Drupal for Education and E-Learning Teaching and learning in the classroom using the Drupal CMS
Published: November 2008
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Books From Packt

Ext JS 3.0 Cookbook
Ext JS 3.0 Cookbook

jQuery UI 1.7: The User Interface Library for jQuery
jQuery UI 1.7: The User Interface Library for jQuery

Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQuery

Learning jQuery 1.3
Learning jQuery 1.3

Drupal 5 Views Recipes
Drupal 5 Views Recipes

Flash with Drupal
Flash with Drupal

Drupal 6 Search Engine Optimization
Drupal 6 Search Engine Optimizationt

Drupal 6 Site Blueprints
Drupal 6 Site Blueprints

No votes yet
Thanks so much for the by
Thanks so much for the detailed explanation, including screen shots (which many tutorials fail to use). I am looking to build a Philadelphia attorney (http://www.philadelphiaattorney411.com) directory that has a social network aspect to it and have been investigating Drupal. Based on your article, it looks like a viable option.

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
T
5
Q
C
q
V
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software