1

I have 3 different roles: Patient, Operator, Nurse. I have one registration form for all my users with basic information (applied via 'Account Settings'). I've been messing around with Profile2 to give each of roles a unique profile.

My problem is that I can't seem to stop Patients from having an Operator Profile and Nurses from having a Patient Profile. Is there a way for me to make the profiles unique to the roles?

I've also considered doing it exclusively in 'Account Settings' and restricting fields using Field Permissions?

I would like to do this so that alternations to the profiles is quick and easy to do.

3

Restricting fields using field permissions would probably be the easiest way to do it; I've had to do something similar with Profile2 in the past and it involves overriding the access callback for profile pages, and checking that the user has a certain role.

Here's some sample code if you want to try it that way:

function MYMODULE_menu_alter(&$items) {
  // Ensure that category profiles are only visible if the user has the correct role
  $items['user/%user_category/edit/parent']['access callback'] = 'zylo_user_category_access';
  $items['user/%user_category/edit/tutor']['access callback'] = 'zylo_user_category_access';
  $items['user/%user_category/edit/school_staff']['access callback'] = 'zylo_user_category_access';
}

function MYMODULE_category_access($account, $type_name) {
  // First make sure the user has normal access to the page
  if (profile2_category_access($account, $type_name)) {
    // Check that the user has the correct role
    return in_array(str_replace('_', ' ', $type_name), $account->roles);
  } 

  return FALSE;
}

It isn't the prettiest but it does get the job done

0

The best solution so far is Managing account registration for multiple user types and you can see the result here: Profile2 Registration Path.

This module enables administrators to set unique registration paths per Profile2 profile type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.