i use the autoassignrole module (and its path based system) to create different user registration forms for each role on my site. and also use profile_role module to restrict profile categories/fields according to role.
but there was no integration between the two. so i couldnt display all the allowed profile fields/categories for a certain role-signup form(provided by autoassignrole's path based role-signup system).
as it is now, it only displays the account(account information) fieldset on the signup form. but i wanted to display all the fieldsets/categories that are allowed for a given role-signup form.
hope that explanation didnt confuse anyone...
anyway here's what i did to achieve integration between autoassignrole and profile_role:
added the following code to the "profile_role_form_user_register_alter" function after line 77 in "profile_role.module"
if (module_exists('autoassignrole')){
$path = drupal_get_path_alias($_GET['q']);
$result = db_fetch_object(db_query("SELECT rid FROM {autoassignrole_page} WHERE path = '%s'", $path));
$form_state['post']['roles'] = array($result->rid => $result->rid);
}
didnt change/delete anything else in the module.
it works perfectly on my site now...
hope boombatower can check this code and add it to the module so we could all get future updates...
cheers!
Comment | File | Size | Author |
---|---|---|---|
#35 | profile_role_register_roles_hook-431454-35.patch | 1.84 KB | stewart.adam |
#17 | integrate_autoassignrole.patch | 879 bytes | larowlan |
#1 | 431454-autoassignrole-integration.patch | 1.33 KB | boombatower |
Comments
Comment #1
boombatower CreditAttribution: boombatower commentedWhat did you use to get autoassignrole_page?
I wrote up a patch that work with the default interface that lets users select their role.
There doesn't appear to be any simple way get around the validation upon selecting of the role. Preferably autoassign_role could do it in two pages. The first select the role and the second redirecting.
Either way let me know what you think of this and then fill me in on the autoassignrole_page stuff.
Comment #2
dj-nitehawk CreditAttribution: dj-nitehawk commentedim using the latest dev version of autoassignrole... in the settings (admin/user/autoassignrole) there's now a section called "assign from path"
which basically lets me tie a role to a path alias... so in profile_role we can determine the role that is associated with the current reg form by looking at the path... which is what the code i submitted above does...
have a look on my site for a working example: http://nzbride.co.cc/user/register (its still in development so id appreciate it if people reading this (other than boombatower of course) wouldnt create any accounts on it)
i tried the patch code and i see your validation dilemma... how about this:
when the selected value of the roles listbox changes, grab the selected rid, append it to the current url as a query item, do a form GET (page reload) with jquery. doing a GET wont fire the validation routines right?
and in the module code, check for the existence of a query item that has the rid to determine if its a role selection and take it from there...
should work right? i dont really know cos im still on my first drupal project and dont really fully understand the drupal FAPI :-)
Comment #3
bdornbush CreditAttribution: bdornbush commentedWhen I applied dj-nitehawk's patch, I found that the categories and roles no longer showed up in the admin/user/profile/role screen. When I deleted the patch, then the categories and roles re-appeared.
I sure hope this can be made to work, as I could use it right now on a new site I have developed that is about to go-live.
Comment #4
boombatower CreditAttribution: boombatower commentedDoes autoassign_role provide a function that returns the selected roles for a user reguardless of the method being used (ie. URL or user selected)? I could not find anything like that, if not I suggest we ask that it be created and then profile_role can use it and can support any methods that autoassign_role does.
#2: I like the idea of the jquery redirect and I'll give that a shot in a bit. (I'm a bit busy at the moment)
Comment #5
dj-nitehawk CreditAttribution: dj-nitehawk commentedhmmm.... weird... cos it works fine on my site...
was it my code or the patch in #1 post that made the roles disappear?
pls note that the code i submitted only works with autoassignrole's "assign from path" interface... and it doesnt do anything for the default "allow the user to choose" interface... and it wont break the default interface either...
we should wait for a working patch from boobatower for support for the default interface...
Comment #6
dj-nitehawk CreditAttribution: dj-nitehawk commentednope... i couldnt find one either... by the looks of it, autoassignrole is determining the method used by looking at the form id and the path... if the path is not /user/register, its an "assigned from path" user reg form...
ill look into this a bit more when i get some free time too...
in any case the form redirect idea should help a lot in the user register form alter... so lets get that sorted first i think...
Comment #7
bdornbush CreditAttribution: bdornbush commentedre #5
I applied dj-nitehawk's code as shown in the base post.
Comment #8
bdornbush CreditAttribution: bdornbush commentedRE #5 and #7
I tried it again. I made one change. I used the path option rather than the tab option. Now it all seems to work fine.
Thanks for solving a big problem for me.
I look forward to a more permanent patch solution.
Comment #9
mdayton CreditAttribution: mdayton commentedsubscribing
Comment #10
cyberswat CreditAttribution: cyberswat commentedIs there anything I need to do to AAR to help this issue?
Comment #11
boombatower CreditAttribution: boombatower commentedI think it a function that does, per #4: "Does autoassign_role provide a function that returns the selected roles for a user reguardless of the method being used (ie. URL or user selected)?" would be great.
And then I think the patch needs to be reworked a bit to provide a better user experience. I think we can reload the form using ahah or something so we don't get the validation errors.
Comment #12
cyberswat CreditAttribution: cyberswat commentedI think this will do what you are looking for?
http://drupal.org/cvs?commit=224798
Comment #13
fabdel CreditAttribution: fabdel commentedExactly what i search for !!!
Thanks.
I use the patch in the #1 post.
But before this patch, i had a common category of profile fields for my 2 roles who was visible, now i must select my 2 roles for using my common category.
Also, i prefer the onclick method to the onchange one.
Finally, is it possible not to submit this form when choosing the role because the message with the required field is displaying.
Hide and show the categories in AJAX ?
Comment #14
Manuel Garcia CreditAttribution: Manuel Garcia commented+1 on this feature... bit reluctant to apply the change mentioned in #1 -- a solution for these modules to work together would be most desirable.
Comment #15
boombatower CreditAttribution: boombatower commentedBeen rather busy, but finally got back to this. autoassignrole_get_roles() seems to have a different purpose then what profile_role needs and is broken in general. Filed issue at: #688934: autoassignrole_get_roles() is broken.
Postponed until I have some sort of API to integrate with.
Comment #16
cyberswat CreditAttribution: cyberswat commented#688934: autoassignrole_get_roles() is broken could use review if anyone is interested in helping boombatower
Comment #17
larowlanHi
I needed different profile fields for different roles (this module) and different registration forms for different roles (different paths).
I found I could integrate profile_role and autoassignrole (path method - not tested with other methods) by adding the following at line 79 of profile_role.module
This just adds the auto role assigned with the current path to the $roles array that is taken from $form_state
Cheers, patch does the same
Comment #18
boombatower CreditAttribution: boombatower commentedThat is exactly what I need...just autoassignrole_get_rid() and have autoassignrole figuere out the rest.
Comment #19
AntiNSA CreditAttribution: AntiNSA commentedCan someone add this to the next dev version soon? I am currently trying to figure out the best strategy to allow different registration modes for different roles and I so far am looking at autoassignrole and content profile..... I think I should add this one into the mix and apply the patch?
Comment #20
fnikola CreditAttribution: fnikola commentedI can verify that this patch works on Drupal 6.14, Auto Assign Role 6.x-1.1, and Profile role 6.x-1.3 when using auto assign role by path on registration. Thanks for the patch larowlan.
Comment #21
izmeez CreditAttribution: izmeez commentedsubscribing
Comment #22
DanBerk4 CreditAttribution: DanBerk4 commentedsubscribing
Comment #23
sjasmeetg CreditAttribution: sjasmeetg commentedI am using auto-assignrole feature "Assign Role From Path" , Autoassign Version 6.x-1.x-dev Version.
I am using Profile Role module version 6.x-1.x-dev version.
I faced the same issue as by dj-nitehaw and applied the patch by dj-nitehawk which worked fine for me. Then I scrawled the page down, found the patch by larowlan. So, I deleted the piece of code advised by dj-nitehawk and copy-pasted the code from larowlan.
Surprisingly the patch by dj-nitehaw is working for me, the patch by larowlan is not working for me. To make things clear, I am using the AutoAssignRole module "Assign Role From Path" feature.
Please help me understanding why dj-nitehaw patch is working for me and if this patch can be checked-in?
I am not an expert PHP developer, so please accept my apologies in advance.
Comment #24
apt94jesse CreditAttribution: apt94jesse commented#17 is quick and perfect. Thanks so much, this is exactly what I needed! I didn't try the other patch, fyi, so I can't confirm or deny, #17 just worked first so I kept it.
Comment #25
mittalpatel CreditAttribution: mittalpatel commentedYeah, the patch in comment #17 is working very fine. Worked for me too...
Comment #26
massyboy CreditAttribution: massyboy commentedvery stratnge to put this at line 79 because in your code you let the variable/array $roles get some value,
but after your code comes a line:
$roles = isset($form_state['post']['roles']) ? $form_state['post']['roles'] : array();
...where $roles is altered again, so that your code becomes partially irrelevant...
Maybe it's best to exactly say just in between which code your snippet should come, because for any reason possible your line 79 may be different to my "line 79"...
So can you define "in between which existing code should your snippet come?"
Comment #27
massyboy CreditAttribution: massyboy commentedI'll reply my own request since I've experimented:
idd if you add the snippet on line #17 you have to comment the line directly after it:
// $roles = isset($form_state['post']['roles']) ? $form_state['post']['roles'] : array();
otherwise it's no use to alter the variable "$roles" in the snippet of #17 ofcourse.
Why didn't this occur to or make any trouble with you guys?
hmmm, that remains a strange inside mystery...
Comment #28
Ela CreditAttribution: Ela commented#17 works for me (as is...) Thank you for the patch!
Comment #29
j0e CreditAttribution: j0e commentedkudos to the original poster for initiating;
using the patch at #17 and works well.
thanks Lee!
Comment #30
massyboy CreditAttribution: massyboy commented...but you get a $roles as result...
and directly after it (without doing anything with the value of $role yet), you'd alter it by:
$roles = isset($form_state['post']['roles']) ? $form_state['post']['roles'] : array();
You see why I commented this line, so as not to overide the outcome of $role by the snippet of #17?
greetz,
Comment #31
ardnet CreditAttribution: ardnet commentedOK, just apply the patch from #17, it work perfectly to me too.
However I got another issue, how to hide the profile fields in the default registration form? (/user/register)
I set up my profile field like this:
- Role 1: Admin (/user/register/admin)
fields:
- field 1
- field 2
- field 3
- Role 2: Editor (/user/register/editor)
fields:
- field 4
- field 5
- field 6
But now, field 1 to 6 is all showing up in default user registration path (/user/register)
Anyone know how to hide these fields in the default registration form? (/user/register)
Thanks
Comment #32
Ela CreditAttribution: Ela commented@ardnet ..go to /admin/user/profile/role to set this up
Hope this helps :)
Ella
Comment #33
daggerhart CreditAttribution: daggerhart commentedPatch in #17 works perfectly. Thank you. This should go into the next release.
Comment #34
gooddesignusa CreditAttribution: gooddesignusa commentedIf this patch http://drupal.org/node/716158#comment-5239290 ever gets rolled in the autoassignrole module can add this code to its module instead of patching profile_role. I added a hook to allow modules to pass a role to profile_roles to show certain profile fields. I needed this for some custom user add pages.
Comment #35
stewart.adam CreditAttribution: stewart.adam commentedAttached patch is based off of gooddesignusa's patch in #716158: create user, select role forces browser to submit page (comment #12) but modified a bit.
This patch makes the following corrections/changes:
This also allows you to very easily implement the hook and have different registration profiles:
You can now use the URLs like /user/register/roleName (for a single role) or /user/register/roleName1/roleName2/roleName3 (for multiple roles). The role names from the URL are translated into role IDs by the hook implementation and you will get the appropriate registration profile fields displayed.
With a minimal form alter hook, you can have also have apply_for_role set its default value to the roles supplied in the URL, allowing you to completely customize the user roles upon registration with any combination of roles.
Comment #36
izmeez CreditAttribution: izmeez commentedThe suggestion of a hook for other modules to use may be the future.
Meanwhile, thanks for the patch in #17. It only seems to work with autoassignrole paths, but helped solve problems using profile_role and have checkbox validation with checkbox_validate module work.
Comment #37
warmth CreditAttribution: warmth commentedIt will be great if both modules get upgraded to Drupal 7, then merged and committed to Drupal 8!