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

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

This article by Bill Fitzgerald, gives an overview of building user profiles. The article begins with the core profile module, and then goes deeper to show how to extend user profiles using the flexible Content Construction Kit and custom fields.

 

The term "social network" means different things to different people. However, the starting point of any network is the individuals within it. A user profile provides a place for site members to describe themselves, and for other site members to find out about them. In this article, we will examine how to create a user profile that is aligned with the goals of your site.

Identifying the Goals of Your Profile

User profiles can be used for a range of purposes. On one end of the spectrum, a profile can be used to store basic information about the user. On the other end of the spectrum, a user profile can be a place for a user to craft and share an online identity. As you create the functionality behind your user profile page, you should know the type of profile you want to create for your users.

Drupal ships with a core Profile module. This module is a great starting point, and for many sites will provide all of the functionality needed.

If, however, you want a more detailed profile, you will probably need to take the next step: building a node-based profile. This involves creating a content type that stores profile information. Node-based profiles offer several practical advantages; these nodes can be extended using CCK fields, and they can be categorized using a taxonomy. In Drupal 6, user profiles become nodes through using the Content Profile module.

The most suitable approach to user profiles will be determined by the goals of your site. Using Drupal's core Profile module provides some simple options that will be easy to set up and use. Extending profiles via the Content Profile module allows for a more detailed profile, but requires more time to set up.

In this article, we will begin by describing how to set up profiles using the core Profile module. Then we will look at how to use the Content Profile module.

Using the Core Profile Module

To use the core profile module, click on the Administer | Site building | Modules link, or navigate to admin/build/modules. In the Core – optional section, enable the Profile module. Click the Save configuration button to submit the form and save the settings.

Once the Profile module has been enabled, you can see a user's profile information by navigating to http://example.com/user/UID, where UID is the user's ID number on the site. To see your own user profile, navigate to http://example.com/user when logged in, or click the My Account link.

Social Networks and Extending the User Profile in Drupal

The default user profile page exposes some useful functionality. First, it shows the user's profile, and secondly, it provides the Edit tab that allows a user to edit their profile. The Edit tab will only be visible to the owner of the profile, or to administrative users with elevated permissions.

Other modules can add tabs to the core Profile page. As shown in the preceding screenshot by Item 1, the core Tracker module adds a Track tab; this tab gives an overview of all of the posts to which this user has participated.

As shown in the preceding screenshot by item, the Contact tab has been added by the core Contact module. The Contact module allows users to contact one another via the site.

Customizing the Core Profile

The first step in customizing the user profile requires us to plan what we want the profile to show. By default, Drupal only requires users to create a username and provide an email address. From a user privacy perspective, this is great. However, for a teacher trying to track multiple students across multiple classes, this can be less than useful.

For this sample profile, we will add two fields using the core Profile module: a last name, and a birthday.

The admin features for the core profile module are accessible via the Administer | User Management | Profiles link, or you can navigate to admin/user/profile.

Social Networks and Extending the User Profile in Drupal

As seen in the preceding screenshot, the core profile module offers the following possibilities for customization:

  • single-line textfield—adds a single line of text; useful for names or other types of brief information.
  • multi-line text field—adds a larger textarea field; useful for narrative-type profile information.
  • checkbox—adds a checkbox; useful for Yes/No options.
  • list selection—allows the site admin to create a set of options; the user can then select from these pre-defined options. Functionally, this is similar to a controlled vocabulary created using the core Taxonomy module.
  • freeform list—adds a field where the user can enter a comma-separated list. Functionally, this is similar to a tag-based vocabulary created using the core Taxonomy module.
  • URL—allows users to enter a URL; this is useful for allowing users to add a link to their personal blog.
  • date—adds a date field.

In our example profile—adding a last name and a birthday—our last name will be a single-line textfield; our birthday will be a date field.

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:

Add a Last Name

Let's start by clicking on the Administer | User Management | Profiles link, or by navigating to admin/user/profile, and then clicking the single-line textfield link. This brings you to the following link: admin/user/profile/add/textfield.

For reasons of clarity, we will break up the administrative form used for adding profile fields. The first half is shown in the following screenshot:

Social Networks and Extending the User Profile in Drupal

  • Category: All custom profile fields need to belong to specific categories. This field allows you to create new categories, and assign your new fields to these categories.
  • Title: The Title will be presented to the user when they are completing the profile form. The value here should be short, and should make sense.
  • Form name: This value is stored within the database, and is exposed in some administrative screens. The form name should also be unique. To avoid any naming conflicts with the names of other fields on other forms, these fields should always begin with profile_.
  • Explanation: The explanation is presented to the person as they are completing or editing the form. Explanations are optional.

    The following screenshot shows the remaining options on the form:

  • Social Networks and Extending the User Profile in Drupal

  • Visibility: This setting allows you to determine who can see the value users enter into this field.
  • In addition to the privacy settings here, access to user profiles can also be toggled ON or OFF for user roles via the permissions for the User module; only roles with access user profiles permissions can see user profiles. These permissions can be edited via the Administer  User management | Permissions link, or by navigating to admin/user/permissions.

  • Page Title: If a field is set to public, you can use the Page title to set up a page where all users are displayed. The next section of this article—Using Content Profile—covers a different method for accomplishing this goal.
  • Weight: This field governs the order in which fields are displayed. These weights can be overridden using a drag and drop interface once all of the fields have been added; refer to the following screenshot for details.
    • Category: Personal Info
    • Title: Last name
    • Form name: profile_last_name
    • Explanation: Enter your last name
    • Visibility: Public field, content shown on profile page and on member list pages
    • As discussed in the prior section, the visibility of these fields is a preference. If you are unsure of what to share between your users, start with a more restrictive selection. From the perspective of your users, adding functionality or options is easier to do than removing them, as people will often miss a feature once it has been removed.

    • Page title: leave blank
    • Weight: -1
  • For the last name field, the above values should be set as shown in the last two screenshots. These values are also listed below:

    When you have adjusted these settings to your desired preferences, click the Save field button to submit the form and save your changes.

Add a Birthday

Adding the birthday field is nearly identical to adding the last name field.

Let's start by clicking on the Administer | User management | Profiles link, or by navigating to admin/user/profile, and then clicking the date link. This brings you to admin/user/profile/add/date.

Form Options

  • Category: Personal info
    • This field will be grouped with the Last name field added in the last section
  • Title: Birthday
  • Form name: profile_dob
  • Explanation:Please enter your date of birth
  • Visibility: Private field, content only available to privileged users
  • Weight: 0
    • This is set to a value lower than the Last name field, so that the Birthday field will be displayed below the Last name field

When you have adjusted these settings to your desired preferences, click the Save field button to submit the form and save your changes.

Managing Your Profile Fields

When you have created your profile fields, you can manage them by clicking on the Administer | User Management | Profiles link, or by navigating to admin/user/profile, as shown in the following screenshot:

Social Networks and Extending the User Profile in Drupal

The edit link allows you to adjust the settings of the individual fields, and the order of the fields can also be rearranged via drag and drop.

Adding Content to a Profile Created Using the Core Profile Module

Users can edit their profile by clicking the My Account link, then the Edit tab, and finally the Personal Info tab, as shown in the following screenshot:

Social Networks and Extending the User Profile in Drupal

Moving Beyond the Core Profile Module

The core profile module is a useful tool for gathering and displaying basic information. However, for more detailed profiles it can become difficult to use. Using a content type to extend user profiles allows us to create more detailed user profiles. Also, using a content type allows us to use CCK to add different types of fields to a profile.

When to Look Beyond the Profile Module

  1. You want to have a blend of public and private information, and you want the public information to be searchable.
  2. You want to have a range of checklists, option buttons, text fields, images, and/or user interests on your profile.
  3. You want more flexibility in what your users can share and display, and you want to set up pages where people can find other people based on interests, likes, dislikes, and so on.

There are multiple options for how to extend user profiles, to the extent that there is an entire group devoted to discussing it at http://groups.drupal.org/profiles-as-nodes.

Extending Profiles Using the Content Profile Module

To extend user profiles, we will use the Content Profile module available at http://drupal.org/project/content_profile

The Content Profile module can be enhanced by using the Automatic Nodetitles module available at http://drupal.org/project/auto_nodetitle. Used together, these three modules provide a simple and effective way to extend your user profiles.

When using the Content Profile module in conjunction with the core profile module, one simple technique for extending profiles involves using the core profile module to store private information (that is, all of the fields created using the profile module are private or hidden), and the Content Profile module to store and organize the public profile.

To begin, install the Content Profile, Token, and Automatic Nodetitles modules. Obviously, if the Token module is already installed, you only need to install the other two modules.

The Content Profile module comes with the Content Profile User Registration module; the User Registration module allows selected fields to be presented to the user when they are registering. This module is covered later in this article.

Once these modules are installed, we are ready to begin building our extended profile.

>> Continue Reading Social Networks and Extending the User Profile in Drupal: Part 2

[ 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 :


Bill Fitzgerald

Bill Fitzgerald was born in 1968, and worked as a teacher for 16 years. During that time, he taught English and History, and worked as a Technology Director at the K12 level. Bill began using technology in his own teaching in the early 90s; from there, he moved on to database design and systems administration. During that time, Bill began developing strategies to support technology integration in 1:1 laptop systems, and in desktop computing environments.

In 2003, Bill and Marc Poris founded FunnyMonkey, a Drupal development shop working primarily within education. Bill started and manages the Drupal in Education group on http://groups.drupal.org, and is active in various educational and open-source communities. Bill blogs about education and technology at http://funnymonkey.com/blog.

When Bill is not staring deeply into computer screens, he can be found riding his fixed gear bicycle through Portland, OR, or spending far too much time drinking coffee.

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
great by
hi this is a very good website

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
8
z
w
S
L
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