2

I'm using Drupal 7.7

I'm working on a module to programmatically add users to an Organic Group. I'm using og_group() and og_role_grant(), but the user is not given full access without also having their group_audience field set correctly. So, my end goal is really to do just that. I cannot find any OG functions that will perform that function, so I'm asking, generically, if there is any Drupal-approved method of writing data into that table.

I've tried using field_bundle_settings(), but I can't get that to work, and I'm pretty sure it won't ever work.

my code is below:

<?php

$settings = array(
    'group_audience' => array(
    'entity_id' => $user->uid,
    'group_audience_gid' => $gid,
    'group_audience_state' => '1',
  ),
);
field_bundle_settings("user", "user", $settings);

thanks

1 Answer 1

0

If you want to create users belonging to a group (able to publish content under the group, see group content), og_group() should do the trick; I'd check your implementation and make sure it's ok before going too far astray. I'm doing the exact same thing with the following code and it's correctly inserting the group_audience values into the field_data_group_audience table.

og_group($group_id, array('entity' => $account));

However, if you're totally stuck and want to try another route, you can always manually insert the data through db_insert().

4
  • Are you trying to add users with a specific membership type to the group (like group admins)? That might be a different case, I'd be interested in hearing a little more about what you're trying to achieve.
    – areynolds
    Commented Aug 26, 2011 at 6:00
  • I'm trying to add users as regular group members. As I said, I've been able to add users to groups using og_group() and og_role_grant() functions, but these functions don't seem to be taking care of the user's group_audience attribute. What's really bothering me (and this may be unrelated) is that I can't get group members to see the body content of a group article (even if I make the member into an administrator and set the group_audience parameter manually). I must be missing something obvious! Commented Sep 6, 2011 at 17:27
  • 1
    Oops. I see what I was doing wrong now. I had enabled og_field_access. This was giving me more granular control that I did not need. It was restricting the fields of the node from displaying. Turning off that module fixed my problem. However, areynolds, your db_insert() is probably the correct answer. Commented Sep 7, 2011 at 15:34
  • Ah, I see. Glad you figured it out; these types of problems are the most frustrating ("this should work...why isn't it working?!"). Cheers!
    – areynolds
    Commented Sep 7, 2011 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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