22997 Posts in 11620 Topics by 2827 members
|Go to End|
30 July 2011 at 8:46pm
Trying to figure out how to change the member / group relationship.
Essentially, I'm wanting to force a member to only be allowed to be a part of one group.
The reason behind this is because I'm using the member profiles module, and when I setup some groups that users can choose to belong to when registering, a CheckboxSetField is supplied so a user can select multiple groups.
In this particular instance, I'm wanting registrants to only be able to choose one group. For example, they can be a "Doctor" or a "Nurse". They shouldn't be able to belong to both.
The CheckboxSetField is pulled using:
$memberFields = Member::currentUser()->getMemberFormFields();
Which makes me think I need to enforce a has_one / has_many relationship in order to be able to pull a DropdownField instead. But maybe I'm wrong making that assumption.
The end result i'm desiring is a drop down box of available groups instead of a checkboxset on the registration form, so if there is a more direct approach to achieving this I'm all ears...
30 July 2011 at 9:35pm
Have you tried removing that field and then adding another one in? Or do you not have access to that bit of the code?
31 July 2011 at 3:02pm Last edited: 31 July 2011 3:02pm
You can customise the fields for the member profiles module by applying an extension to the Member class and using the updateMemberFormFields hook. Just removing the groups field and replacing it with a dropdown will change the form field. You might need to customise the saving logic a bit though.
31 July 2011 at 4:07pm
Thanks Colin and thanks aj - that has given me some food for thought. I'll report back with how I get on ;)
1 August 2011 at 5:28pm
Thanks again for the direction. Got me where I needed to be with this, so fantastic.
To make this work, I created a separate DataObjectDecorator which uses the updateMemberFormFields hook to remove the existing groups field, and add a new empty DropdownField.
Then, in MemberProfilePage.php, I edited a couple of lines....
When setting the source of the Groups field, I updated setSource to:
Finally, as mentioned by aj, I had to update the saving logic. In getSettableGroupIdsFrom, I removed a foreach loop on the group value as Groups is now a single value.
There was probably a way to do this without having to edit MemberProfilePage.php directly, but hey it's working...
25 January 2012 at 12:07pm
can you share your code, I am keen to do the same thing
|Go to Top|