How to add user to some group during registration AUTOMATICALLY

Events happening in the community are now at Drupal community events on www.drupal.org.
playfulwolf's picture

Hi,

Have some kind of "default" group, and want user to became user of this group automatically during new user registration.
There is a similar module, but I want full automation.

How to write a rule for that?

Comments

Look there:

paul_constantine's picture

Solution at https://groups.drupal.org/node/305883

Two solutions. Just scroll down a little.

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Do it in code

forestmars's picture

I noticed that the 2 solutions referenced above use Rules, and are a bit messy. Here's a simpler solution in code I wrote that I think is a much neater approach. Obviously set $gid to the group you wish to add new users to:

/**
* Submit callback for user_register form.
*/
function codify_user_register_submit($form, &$form_state) {
  global $user;

  // Automatically assign users to a particular group.
  $gid = 1;
  $uid = $user->uid;

  $account = user_load($uid);
  $values = array(
      'entity_type' => 'user',
      'entity' => $account,
      'state' => OG_STATE_ACTIVE,
     );
  og_group('node', $gid, $values);

This was implemented in COD (in the Codify module, actually) for the first year of NYC Camp. In subsequent years, users can login with their existing accounts and self-register for a new annual event. That of course is slightly more complicated…

As for me It says “Unable to

castor-designs's picture

As for me It says “Unable to parse the pasted export.” Any idea why?

Is this complete?

nrackleff's picture

Does the module end after the line og_group('node', $gid, $values); ? I ask because the curly brace does not close and I was wondering if there was more that didn't get displayed. Thank you.

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: