I recently created Profile Registration Path, a module that enables administrators to set unique registration paths per Profile2 profile type.

It would be great if we could integrate this module with AutoAssignRole such that users can be assigned roles automatically if coming from a specific registration URL. I believe that in Drupal 6, this integration was offered for Content Profile

It seems like this would be a fairly straightforward task. It may be best accomplished by adding AutoAssignRole fields to the profile2_type form with hook_form_alter(). Beyond that, we'd just need autoassignrole_user_presave() and autoassignrole_form_user_register_form_alter() to check on arg(3) before making any role assignments.

Please let me know if you'd like to collaborate. I'd be happy to add any hooks or utility functions to Profile Registration Path to make this easier.

Thanks!

CommentFileSizeAuthor
#2 add_hook-1334412-2.patch1.35 KBgrasmash
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aceiscracked’s picture

following...very interested in conditional paths to create profiles and link to roles.

grasmash’s picture

Status: Active » Needs review
FileSize
1.35 KB

I've added a few simple lines of code that define a new hook: hook_autoassignrole_add_role();

This will allow other modules to supply autoassignrole with an array of role ids that should be added to the $roles_to_add array during hook_user_presave();

Using this hook, I've integrated the dev version of profile2_regpath with autoassignrole so that admin can specify roles assignments per registration path.

This method seems to be the most efficient means of adding role-by-path functionality.

RKS’s picture

@madmatter

Right now this effort with autoassign is located here Administrator configures registration paths, each with customised [sic] role assignments

Both of these issues have patches so I think the best effort is to combine efforts and see what's what. In that issue there was a patch supplied without anything in install.inc so the patch is unusable currently. I've made some effort to contact the patch poster but so far there hasn't been any response.

As for your patch, are you saying this solution is working? Or that you've set it up to be a launching point for this functionality? I.e. using your patch and module users can define registration paths right now?

halmsx’s picture

thanks for the module =)

grasmash’s picture

Hi RKS,

Using this patch and the dev version of Profile Registration Path offers this functionality right now. The solution is working. I'll have to do some more testing be be sure that there aren't any bugs, at which point I'll push the commit to a true release.

I did see the work being done in the issue that you linked. I couldn't use the patch (given the missing .install file) but it did seem like quite a lot of code for this one feature.

It also seems to be a bit out of the scope of autoassignrole. Most often, separate registration pages are used for the purpose of catering to different user types, each requiring different information to be gathered during registration. Consequently, the use of Profile2 to define multiple profile types is likely going to be involved. It makes sense to me that the profile module should be responsible for defining registration paths and the associated roles.

The only requirement would be an autoassignrole hook that could be utilized by a profile or registration contrib module, permitting those modules to pass off an array of roles to be added to autoassignrole's normal role assignment process.

Sorry if that was a bit long winded! Please let me know if you think another path would be more advantageous. I'm open to changing our approach.

Thanks!

RKS’s picture

I think your approach is just fine. If it works, it works for me. The only thing I could think of was the two different use cases.

1) Admin wants path-based auto roles AND wants customised registration pages. Solution: Profile2+Profile2 Path Registration+Auto Assign Role. Works perfectly.

2) Admin only wants Auto Assign Role by Path. Solution (right now): Auto Assign Role+Profile2 Path Registration+Profile2.

In the second use case, they are forced to install Profile2 which is useless for their use case. So if you think of use case #2, Auto Assign Role needs the functionality itself as the other thread I mentioned is trying to implement. The use of Profile2 is an unneeded module.

However if you go off use case #1 (which is where my use case falls into) having registration in both modules is a duplication of effort. I need all three of these modules, two of which are providing very similar functionality and hopefully isn't going to conflict if Auto Assign Role ever puts this into their module.

As for me, thanks for posting your module and working out this solution. Like I said it works perfectly for my use case.

RKS’s picture

Status: Needs review » Reviewed & tested by the community

I have tested this patch and it works on a clean dev install and on a live site. The solution provided by madmatter works and has also been tested in dev and live.

An extra tip for anyone reading who wants to set up this solution: When configuring Auto Assign Role under admin/config/people/autoassignrole enable Automatic and User Selects options but do not select an automatic or user select accounts. if you do, all forms will allow users to select a role. If you're really wanting to do it by path only, leave these blank in configuration.

Then under structure/profile when you create a new profile it will allow to to enable a registration path, and then select the role to assign automatically when registration is completed. So even though you leave the autoassignrole settings blank, you will be able to select it for the profile you want to assign via path.

grasmash’s picture

Thanks RKS,

I've added a note to the profile settings page indicating that autoassignrole must be enabled.

On additional comment: enabling automatic or user chosen role assignments in combination with setting profile-specific roles does work. It will simply combine all specified roles.

jdfx’s picture

RKS - in my case your second use case is applicable - Admin only wants Auto Assign Role by Path, it would be nice to not have to install Profile2 in mycase.

Also - thanks madmatter, got the solution working with the Dev release of Profile Registration Path and the above mentioned patch to auto-assign role but there's a very minor error in the code for the Dev release of Profile Registration Path, line 210 has an un-necessary closing '}' that was causing everything to break until I removed it. Once removed everything worked fine, as a heads up.

Thanks.

grasmash’s picture

thanks for the heads up jdfx. I've fixed the syntax error in the dev version.

grasmash’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

**UPDATE**
After receiving no response from AAR maintainers, I have removed AAR integration from Profile2 Registration Path.

Automatic assignment of roles during registration has been made native to the Profile2 Registration Path module.

I still think that adding this hook would be nice, but I no longer require it. Thanks!

tiboe’s picture

Status: Closed (works as designed) » Needs review

#2: add_hook-1334412-2.patch queued for re-testing.

WorldFallz’s picture

Status: Needs review » Closed (works as designed)

please don't play with issue statuses unless you know what you are doing. Thanks.