For the Quebec Chronicle-Telegraph website, I was asked to create a system whereby users could sign-up for one of three types of newspaper subscription, and at the same time, get a user account with access to premium content. Each of the three subscriptions would require different information from the user. This requirement precludes the use of the regular core profile module (that module provides one set of profile fields for all roles).
After some searching on drupal.org and some Drupal user sites, I figured out a way to do this using Role Signup and Node Profile modules as the two main modules. There were several other supporting modules that I used to fill in a few of the "gaps".
So how exactly did I do it? Read on and find out...
Modules used
- Role Signup
- Node Profile
Requires: - Auto Node Title
Requires: - CCK
Extra CCK widgets
Module modifications
Role Signup
This is a great module, but we needed some extra features. By default, the module simply shows the various roles that you are allowed to choose from. However, we wanted to have a description for each role - subscription cost, what you can do with this type of subscription, etc.
What I did was add in some code that allowed descriptions to be added to each role. These descriptions could be entered through a settings menu in Administer > Settings > Role Signup. I also added the ability to change the name of the role shown on the registration page. This allows you to keep simple role names, but show a more descriptive label for the role e.g. the citizen role can be displayed as Regular subscriber. One final modification was the ability to sort the user roles in various ways (sorry, I didn't use weights, as I could achieve the desired sort order with the options I provided). I have submitted a patch for this functionality, by the way.
CCK widgets (optional)
I modified the Address and Fullname widgets a bit as some of the code that was outputted wasn't quite up to spec. If I could do it through theming, I did, but some of the code was hardcoded.
Configuration
- Install and activate all of the above modules - the extra CCK widgets are optional.
- Configure Role Signup
- select which roles you want shown on the selection screen
- go to admin/user/access and tick the box for the desired roles
- add descriptions and titles, and choose the sort order if you use the above patch.
- Create a new content type using CCK, for each role:
- open the Automatic title generation fieldset
- check Automatically generate the title and hide the title field
- create a pattern for the title
- enter your Name and Type data
- leave the Title alone as Auto Node Title will take care of it
- you can leave the Body field as is, or remove it - I usually remove it, so that I will have more control of the fields
- in Default options, uncheck Promoted to front page
- enter "1" for Maximum population
- tick Use this content type as a nodeprofile for users
- disable comments
- Save your node type
- Click edit to open up your new content type
- Add and configure the fields you want to your node type
- Click on Node profile and tick the following options:
- Integrate this node profile with user categories
- Show this node profile during user registration
- select the role(s) that will use this node type
- Display it as full node view
- Include an edit link to the display (default)
- Include an add link to the display if they haven't yet (default)
- Click Update
- Finally, go to Access Control and allow the different roles to Create & Edit the node types that relate to them
That's it! Logout and go to user/register to see what happens. You should see a list of your roles (with descriptions if you used the patch). Click on a role and you should see the node type you just created for that role. Fill it in, and an account should be created for you. The details you entered should be visible on the My account page. They can be edited by clicking the Edit link just above the profile, or by going through the regular profile edit tab and selecting the node type.
If you need to customize the layout of the various fields, you will have to do some theming. You can use the Contemplate module to do this, or create a node-nodetype.tpl.php file for each node type.
By "pattern" I mean how you want the title to look like, using the tokens provided (look just below the title field for "replacement patterns"). I usually do something like: [author-name] [author-uid].