1

I wrote a custom module to add a VBO action that allows an Admin of a group to search the sites users, add them to their list (adds a role to the select users to get them on the list) and then allows the Admin to optionally add the user to an organic group they also may admin. The role is added just fine, but the organic group won't 'stick' unless I enqueue the operation. When I don't enqueue the operation, I dpm'ed the call to og_group and it's returning a membership object and claims it was successful, but it clearly didn't save. I don't have any errors or notices in the logs either. Here's my setup for saving the group/user relationship:

$values = array(
        'entity_type' => 'user',
        'entity' => $user,
        );

og_group('node', $group->nid, $values);

$user is a fully loaded user account and $group is the group node. I tried adding name_field and the group audience to the values array, but this made no difference.

Here's the hook for the VBO:

function vbo_users_to_groups_action_info() {
 return array(
   'vbo_users_to_groups_my_custom_action' => array(
   'type' => 'user',
   'label' => t('Add users to Pro List and optional Group'),
   'behavior' => array('changes_property'),
   'configurable' => TRUE,
   'vbo_configurable' => FALSE,
   'triggers' => array('any'),
   ),
  );
}

Is there anything else you need to see that may be causing this?

1 Answer 1

0

If anybody runs into this in the future, I had to pass the group id into the og_user_node field and save the user after calling og_group():

$values = array(
    'entity_type' => 'user',
    'entity' => $user,
    );

og_group('node', $group->nid, $values);
$data['og_user_node']['und'][0]['target_id'] = $groupid;
user_save($user, $data);

You should check for any other groups the user is in and create an array of groups along with the new group id and save that into og_user_node, but in my situation, users are only allowed in 1 group, so this takes care of putting them in the new group and removing the old one.

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.