When people register for my site I want them to either join an existing group or create a new one if it doesn't exist. They can only be a member of one group, and there's only one group type used on the site.

I've got the autocomplete widget set and I want to alter it's functionality so instead of throwing an error message it creates a group. I presume altering og.module is not a good idea as it wouldn't be easy to make my particular changes generic enough to work for lots of use cases so am I right in thinking I would create a custom module to hook into the pre-save functionality of the user entity and do my checking to see if exists, if not then create group and create membership there or is there another way?

I tried using taxonomy as my group content and using a term reference autocomplete field on my user profile, but og doesn't seem to work fully with taxonomy at the moment, and I had other problems with attached field data not saving on taxonomy so gone back to using a node type as my group content type.

Comments

dgastudio’s picture

did u found any solution?

amitaibu’s picture

Why not use OG-register module?

dgastudio’s picture

create a new one if it doesn't exist.

amitaibu’s picture

Oh, in that case you will have to do it via custom code -- create a new node, and og_group() the user to that node. Shouldn't be too many lines of code :)

dgastudio’s picture

right now i'm solving it with rules.

Anonymous’s picture

Thinking back I ended up adding group functionality to a taxonomy vocabulary so the autocomplete widget worked and automatically created a new "group" if a term didn't exist.

At the time I did this (nearly a year ago now!) the group functionality on taxonomy terms wasn't as complete as it was for other entities so my final word on this is "YMMV" ;)

stevebab’s picture

@amitaibu Loved the video with Ban Ki-moon. You are very good at communicating how OG works. Thank you.
@kervi Looking at doing this with rules. Would you by chance be willing to explain how you did it? Which rules/actions/conditions?

scottsawyer’s picture

I also want to create a group with rules when a user registers with a certain profile2 path.

Where I am currently:
I have two profile2 profiles with profile2_registration_path, auto-assign role based on path:
1st profile - Teacher - teacher/register - assign "teacher" role
2nd profile - Student - student/register - assign "student" role

I want to auto-create a group "Class" when a teacher registers.

My rule so far:

Event - After saving new profile
Condition - User has role(s) - teacher
Action - ??? - no action available for creating a node or creating group.

Please, if anyone has a brilliant idea, I am all ears.

scottsawyer’s picture

Ok, I have it working with Rules...

Event - After saving new profile
Contition - User has roles - teacher
Action - Create New Entity - Content Type - Group (I guess it will be class.

Step 1 complete. Now for all the other questions I will have. At least this may help someone get started.