Drupal 7 Profile 2 Module
Share with Others
The Drupal 7 Profile 2 module is a great module for extending the information you collect and display about Users on a Drupal 7 website. The modules allows the separation of profiles from the traditional User entity and allows you to build complex Drupal sites with multiple profile types. This is useful for building Drupal social networking sites along with many other use cases.
In this episode you will learn:
- What the difference is between the core Profile module and the Drupal 7 Profile 2 module
- How the Drupal 7 Profile 2 module differs from just adding fields to the User entity
- How to set up multiple Profile2 profiles on a Drupal 7 site
Hello there Drupal cadets and today we are going over another exciting episode of the Daily Dose of Drupal. Today we’re on Episode Number 33 but before we start I’m Shane, you can contact me on Twitter @smthomas3 or go to codekarate.com and reach out to me there if you have any questions or if you just want to say hi. Today we’re going over the Profile 2 Module and this is only available for Drupal 7 and the reason we’re going over this today is someone reached out and ask for a tutorial on the basics of the Profile 2 Module.
Basically; there used to be a Core Profile Module in Drupal 6 and actually it still is there in Drupal 7 but it has been deprecated as you can see it from the message which basically means it probably shouldn’t be used, it’s only there to help with an upgrade from a Drupal 6 site to a Drupal 7 website.
This module … if you’ve used Content Profile Module in the past, for the most part it replaces the Content Profile Module, there may be some needs for the Content Profile Module in Drupal 7 but for the most part this would probably cover what you’re looking for.
And so we’ll go over what you can do with this. The first question you may ask is well what is different about the Drupal Fields that you can add to User Content or User Types in Drupal compared to the Profile 2 Module and why would you need to use the Profile 2 Module if you already have fields on the User Entity in Drupal 7.
Well you can think of the Profile 2 Module as serving a type of separate entity from the User Module or the User Entity, and what that means is you may want the user settings for the specific user to be just your e-mail address and your password and it carve more of a settings type of page and then you want separate profiles and this also can be extended so someone could have multiple profiles.
You may have a Developer Profile and a Designer Profile if you’re on some type of technology website or basically it allows you to separate the profile from the actual account settings. So if I come to my account and I edit this, I may want to keep these settings as more of configuration type things and have a separate section for my actual profile where I can have information bio, use social network links, that type of thing. So it’s probably something you’ll use if you’re building any type of social networking sites or a similar type of Drupal websites.
We’ll go ahead and get started though; I’m going to get started by downloading Drush … we’re using Drush, the Profile 2 Module, you can see it comes with three modules, Profile 2 page, Profile 2 OG access and Profile 2. We’re not going to be using it with organic groups so we won’t use the OG Access 1 but I will go over the two modules. And we’ll start by just installing the profile 2 module, we also need to enable the Entity API Module so you’ll have to have the Entity API Module as well and I can go ahead and I can look at the permissions here and you can see that there are a couple of permissions but there’s these main profile permissions, allows the user … right now the authenticated user to edit their own profile and view their own profile and that comes default but you can of course change it.
If we go back and we look at the Configuration page for Profile 2 you can see that there’s one profile and we’ll start with that but we can go ahead and add another one here a little later in this tutorial. So we’re going to go to Manage Fields and we’re going to add a First Name, we’ll just go Full Name, keep it simple, so we’ll add the Full Name field and we will add a Bio Field, we’ll make this a long text with multiple rows, we’ll leave it at the defaults and click Save.
And now we’ll show you how this works; we will click onto our main My Account or User page and if we go into Edit you’ll notice that there’s nothing … there are no additional fields added here but there is a main profile … a little sub-tab here. If you click on that you can see that I can add my name, add a little bit of a bio, click Save.
Now if I go to View you can see I have a Main Profile section as well as what was already there before. So that’s the Profile Module or the Profile 2 Module and as you can see it’s pretty simple, allows you to extend the traditional Drupal Profile or Drupal User Accounts, I’m going to add additional profile information but we’ll also go ahead and turn on the Profile 2 Pages Module, save that and you’ll notice it doesn’t have any type of configuration pages.
This is still the same so we’ll go back to our homepage, click on My Account and you’ll notice that this information is gone, if you come into Edit you’ll notice there is no longer a tab here either for editing your main profile. It actually has added a separate page for your main profile. So now if I click on Main Profile I have a separate page with My Profile on it and a separate Edit Page for that. Basically breaks the profile out so it’s completely separate section from your My Account in your account settings.
Just to show what you can also do as far as adding additional profiles; we’ll come back into Configuration, we’ll go ahead and go through it this way, a little bit quicker here and we’ll add a Profile Type and we’re going to go ahead and call this a Reviewer Profile, I do have another role on my site for Site Reviewer that I had created in the previous tutorial.
So I’m going to allow these types of users to have additional or an additional profile page, I’m just going to add one page called Reviewer Bio so you can get the idea, I obviously could have a lot more fields, I could have images, anything I wanted in here but we’re just going to keep the fields pretty simple, I’m going to come in to the permissions again, refresh and find the Profile 2 section and I want to give the Administrator all those and I want to allow the Site Reviewer to edit their own profile for Reviewer profile and view their own.
So keep it pretty basic there, I could of course give anonymous users the ability to view profiles, things like that but we’re going to just keep the permissions pretty basic for now just to show you what it can do. Now you will notice that I have this Masquerade Module which I went over in a previous episode of the Daily Dose of Drupal so you can look at that if you’re not sure what this does. This will be basically allows me to log in here as a regular authenticated user.
You can see that I have Main Profile, I can edit it, I could say … just fill out some information, I now have a profile, I have it on My Account section, I can change my password, my e-mail address, things like that, if I switch back and I come back here I can also log in as a reviewer and this user has that reviewer or site reviewer role that I’ve showed you and now I can see I have an extra section for my reviewer profile. So I have my Main Profile, I have my Reviewer Profile and I also have My Account Section.
So that’s really all there is to it, you can see that it can be used to create different types of profiles where you can collect different information about Users and separate them out into distinct profiles section depending on if you need multiple and it separates it from your My Account settings.
So there’s a lot of flexibility in building this out, you can use it for a lot of different purposes. The main use I see it being use for is larger social networking type of websites built with Drupal but there’s a whole bunch of other use cases as well. Thanks for taking the time to watch the Daily Dose of Drupal, follow me on twitter @smthomas3 and we will be back again next time with another episode, thanks for watching.