0

I would like everyone to be a member of "our Community" by default.
I want everyone to be a member of a site-wide group so that we can have a site-wide wiki, events & all the other usual group stuff.

Do I miss the point? Is this already the case, or do I not really want what I think that I want?

1

Well, you could code it, but it's kind of a cheesy solution. Assuming you have a group called "My Group" you want everyone to join, you could write some code and embed it on a page that everyone hits. As soon as they land on it, they get added to the group automatically. PHP/Drupal code might look something like this (Drupal 7 example):

//get the user's id
global $user;
$uid=$user->uid;

//get the group's GroupID
$result=db_query("SELECT gid FROM og WHERE `label`=:groupName",array(':groupName'=>'My Group'));
$row=$result->fetchAssoc();
extract($row);

//check and see if the user is a member of the group already
$result=db_query("SELECT COUNT(id) AS og_count FROM og_membership WHERE etid=:uid AND gid=:gid",array(':uid'=>$uid,':gid'=>$gid));
$row=$result->fetchAssoc();
extract($row);
if($og_count==0 && $uid!=0)
  {
  $result=db_insert('og_membership')
  ->fields
    (
    array
      (
      'name'=>'og_membership_type_default',
      'etid'=>$uid,
      'entity_type'=>'user',
      'gid'=>$gid,
      'state'=>1,
      'created'=>time(),
      )
    )
  ->execute();
  }

This is not the preferred way to do it, but in a pinch you could add this code to a heavy traffic page and pretty much ensure your users get added. The down side is that you are doing an extra database dip or two to ensure your users are added to a specific group. Not very efficient, but it would likely do what you want.

As a caveat, this is based on what I know from playing around with Organic Groups. This code is from the top of my head, so there may be a parsing error here or there - be sure to check it out first. Also, this is direct dipping into og's table structure, which is frowned upon, as og could change their table structure in the future, during a code update...

|improve this answer|||||
1

I think you could use the Organic Groups - Multiple Mandatory Groups by Role module.

The goal of this module was to extend the capabilities of the original og_mandatory_group module to allow as many mandatory groups as the user wants for:

  • All users
  • Group administrators/owners
  • any role

As all of the changes constitute a module with drastically different capabilities, it didn't make sense to patch the original module with this code. Additionally, most of the old code was thrown out and a ton of new code put in place.

|improve this answer|||||
1

I am not sure, but if Organic Groups has rules integration; you might be able to create a Rule which automatically adds the user to the desired group.

|improve this answer|||||
1

Use the Rules module. After a user registers, run PHP code that would add that newly registered member to a group. Then add a call to drupal_set_message(), notifying them that they are automatically member of a group.

|improve this answer|||||
0

In organic groups module you can set the "user: group audience field" to required and "show on registration page" in combination with the "show all groups" setting. That will force the user to select a group from the list when signing up.

I've only tested this in Drupal 7 but I'm pretty sure Commons uses organic groups as well.

|improve this answer|||||
0

I don't see any options such as Organic Groups offers.

The best that I could do is add some text to the registration guidelines and welcome email strongly recommending to join the group "Our Community".

I also made it a "featured group" so that it will appear on the front page.

Aha! If I (log in as admin and) edit the group, I see the option "Registration form May users join this group during registration? If checked, a corresponding checkbox will be added to the registration form" ... but that still doesn't enforce membership :-(

|improve this answer|||||
0

what I found was this:

If you have one public group and all the rest are private groups, new members are added to the public group by default. May not help everyone but it solved the issue very easily for my use case.

I believe it is also necessary to edit the Group content type - Group Audience and/or - Group visibility fields and check the "required" box

Sean :)

|improve this answer|||||
0

You can do this programmatically.

Write a custom module that implements hook_user_insert. In hook_user_insert, call og_group, which subscribes an entity to a group. So your .module file looks something like this:

/**
 * Implements hook_user_insert().
 */
function mymodule_user_insert($edit, $account, $category) {
  $values = array(
    'entity_type' => 'user',
    'entity' => $account->uid,
    'field_name' => 'field_group', // Must be the name of the field in user that references groups
  );

  og_group(group_type, group_id, $values); // replace group_type and group_id with the entity type of the group and its group id
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.