Custom role-dependent user profiles

 

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...

UPDATE (22/03/2008): The Role Signup module has been deprecated in favour of the Auto Assign Role module. However, the role selection is now on the same page as the profile fields, so you cannot use it with nodeprofile to get different signup forms at this time. Because of that, I am providing the patched version of Role Signup here.

Modules used

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

  1. Install and activate all of the above modules - the extra CCK widgets are optional.
  2. 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.
  3. 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
  4. Click edit to open up your new content type
  5. Add and configure the fields you want to your node type
  6. 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)
  7. Click Update
  8. 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].

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值