Start a FREE 7 day trial! Get training videos and books, plus expert support:  

Drupal Tutorials and How-to Support Articles

Improving Drupal User Profiles with Profile2

drupal-profile2Drupal 7 has made it easy for you to allow your site users to share information about themselves. User accounts are now "entities" which means that you can add fields to them, just as with content.

You can add user profile fields for names, email addresses, phone numbers, resumes or whatever else you might need.

However, there are some limitations to the core user profile. What happens if you don't want user accounts visible to the public? What happens if you need different profiles for different areas of your site?

The answer is the Profile2 module.

Profile2? Drupal 6? Drupal 7?

Profile2 is only available for Drupal 7 sites.

For those of you with experience building sites in Drupal 6, let me explain why it's not needed for Drupal 6. In Drupal 6 you have the core Profile module. However, that did not make it into Drupal 7.

The Content Profile module was also a good option for Drupal 6 sites.

In Drupal 7, the Profile2 module creates a profile entity similar to how a node is an entity, a user is an entity, a vocabulary term is an entity. Because profile is an entity, we can add fields to it and we can have more than one.

To understand what Profile2 does, let's take a look.

The default user profile

By default, Profile2 provides one profile type. You can see an example below. The screenshot shows that we have added three fields to the main profile: image, name, and bio.

media_1357318737630.png

Install Profile2

There are two modules required for Profile2 to work.

Install the modules to your site and you will be able to see them in your module list.

  1. Click on Modules in the black admin menu bar.
  2. Check the box next to Profile2 and Profile2 pages.
  3. Save configuration.
  4. Drupal is smart enough to know which modules are required and will now prompt you with a list of modules it will enable for you. They include the Entity API module.
  5. Click continue to finish enabling the modules.

Configure the Profile2 module

  • Go to Structure > Profile types.
  • Click Add profile type.
  • You'll now be able to add a completely new profile type with different fields and different display options.
  • The screenshot below shows the default main profile and the Community profile I added using the Add profile type link shown on the screen.
media_1357319435116.png 

Edit the Profile Type

As you can see from the screenshot below, there are just a few options to consider for each profile type.

media_1357319628739.png
 

The first checkbox will give the users access to their profiles if they edit their user accounts.

The second option will add links to the profiles to the User menu so that your users can edit them. Here's how the profile links might appear:

media_1357319003827.png

Add Some Fields

From inside the Structure > Profile 2 area you can add field to each profile type. 

media_1357319903411.png

Other Configurations to Consider

In addition to the settings discussed above, below are few others to consider.

  • User Accounts: You still have the option of adding fields to your user account but you'll want to plan which ones will be a part of the user account and which will be on the profile. You don't want your users duplicating effort if not necessary.
  • Roles: If you want the profiles to be available to specific users on the site, consider added a role that can be assigned to a user and thus give them permission to view or edit the profile(s).
  • Permissions: Whether you have a separate role or not, remember to set permissions (see your options in the screen shot above).
media_1357320133173.png

Summary

If you are having a hard time envisioning how Profile2 can be used on your site, consider the following use case (borrowed from https://drupal.org/node/1114454 .)

"One profile stores contact information (address, city, etc) and this information through the permissions is able to be edited by the user. The second profile is information that is related to a user's membership, so things like membership ID, year joined, etc. This information is such that it can be viewed by the user, but not edited."

 

Start a FREE 7 day trial! Get training videos and books, plus expert support:  

License

All of our tutorials are published under the Creative Commons Attribution-NonCommercial license. This means:
  • You can re-use these tutorials.
  • You can modify these tutorials.
  • You must link back to our original tutorial.
  • You can't use these tutorials commercially.
Click here to read the full license.