Auto-create og on user registration

mgerra - October 11, 2006 - 15:59
Project:Organic groups
Version:4.7.x-1.x-dev
Component:og.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I'm looking for a way to automatically create an organic group when a user first registers.

Ideally, this would be based on the user's username, email address or other unique identifier, with the group added behind the scenes. All other og admin functions would remain, such as og delete, add users etc.

Is it possible that this function has already been implemented somewhere? Yes, I'm trying to avoid writing it myself.

Many thanks. OG is a GREAT piece of work!!

#1

moshe weitzman - October 11, 2006 - 16:38

i don't think it exists but the logic will be something like og_mandatory_group which also acts upon registration.

#2

moshe weitzman - October 15, 2006 - 13:04
Status:active» closed

some other module will need to implement this.

#3

juicytoo - July 12, 2009 - 07:33

is it possible to do this now with drupal 6 and rules?

Thanks in advance.

#4

mackh - July 12, 2009 - 08:40

I haven't done this with rules, but it should be possible. You can make a small custom module that adds a group node for each user that registers, possibly by implementing a _user hook in your module. (http://api.drupal.org/api/function/hook_user/6)

Here's the code that you could call in an action your hook, essentially builds the basic for the group node specific to the user, and saves it.

Hope this helps, and I'm sure there is a smoother way you could do this...
-M

$gnode = array();
$gnode['type'] = 'group';  (your group type name may be different)
$gnode['status'] = '1';
$gnode['promote'] = '0';
$gnode['title'] = $form_values['groupname'];  (user's group name)
$gnode['body'] = $form_values['mission'];    (some value from your reg form if like)
$gnode['og_description'] = 'empty';
$gnode['og_register'] = 0;  (don't show in reg form)
$gnode['og_notification'] = 1;  (enable group notification)
$gnode['uid'] = $user->uid;  (set the group node uid)
$gnode['name'] = $user->name;  (set group owner name)
$new_group = node_submit($gnode);
node_save($new_group);

#5

juicytoo - July 19, 2009 - 12:12

Thanks for replying.

I'll have to wrap my head around this one ;-)

#6

paul_constantine - July 20, 2009 - 06:51

Did you get this working?

I am running a couple of Drupal 5 websites and I would like to implement something like this too?

But I am not a programmer.

Regards,
Paul

#7

VinceW - September 2, 2009 - 00:05
Status:closed» needs review

@juicytoo #3

Yes it can be done with D6, Rules and Tokens. This in a very basic way. With tokens you can pull off some required data of the user form and use that for instance to create a OG name.

I assume when using content_profile you can have more fields to pull the desired data from. (or have a look at http://drupal.org/node/23710 to Create new profile fields)

Best,
VinceW

-=[ Your Information Matters ]=-

PS: I didn't change the version since it was initially a D4 issue in 2006. I've set the status to "needs review" because I would like to have more people looking into this solution in case I've overlooked some modules created after 2006.

#8

juicytoo - September 3, 2009 - 07:15

Thanks Vince,

I'll try and wrap my head around this.

cheers

#9

Tim_O - November 9, 2009 - 22:33

I did this with og and rules. One problem persists though, I cannot set those created groups to be private, but otherwise it's doable. This is with OG 6.x-2.0. I used the following rules on trigger "user account has been created":
1) create node (group-type)
2) add group node settings to that node
3) save node
I additionally stored the nid of that group in a user-profile as described in #609992: PHP code to change custom profile field. So consider this solved for the current version.

 
 

Drupal is a registered trademark of Dries Buytaert.