I created a custom module to add a global Drupal role for every og group admin by using OG's hooks. But I get a string of errors when user_multiple_role_edit() is present. I haven't been able to figure out why. The uid is present so you'd think it would easily work. But perhaps it doesn't work wherever user_save() is used. I looked for similar issues and just came up with this one: https://drupal.org/node/1411944

function MODULE_og_role_grant($entity_type, $gid, $uid, $rid) {
  // Code here to check if user is a og group admin

  user_multiple_role_edit(array($uid), 'add_role', 4); // where global Drupal role "group admin" is 4
}

The errors:

Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 157 of /var/www/vhosts/www2.ctsnet.org/htdocs/sites/all/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php).
Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 160 of /var/www/vhosts/www2.ctsnet.org/htdocs/sites/all/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php).
Notice: Trying to get property of non-object in OgBehaviorHandler->groupAudiencegetDiff() (line 168 of /var/www/vhosts/www2.ctsnet.org/htdocs/sites/all/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php).
Warning: array_flip(): Can only flip STRING and INTEGER values! in EntityAPIController->load() (line 219 of /var/www/vhosts/www2.ctsnet.org/htdocs/sites/all/modules/contrib/entity/includes/entity.controller.inc).
Notice: Undefined property: stdClass::$original in file_field_update() (line 265 of /var/www/vhosts/www2.ctsnet.org/htdocs/modules/file/file.field.inc).
Notice: Undefined property: stdClass::$original in user_save() (line 552 of /var/www/vhosts/www2.ctsnet.org/htdocs/modules/user/user.module).
Notice: Trying to get property of non-object in user_save() (line 552 of /var/www/vhosts/www2.ctsnet.org/htdocs/modules/user/user.module).
Notice: Undefined property: stdClass::$original in user_save() (line 560 of /var/www/vhosts/www2.ctsnet.org/htdocs/modules/user/user.module).

Comments

drupal_was_my_past’s picture

I'm not getting errors, but I think I am experiencing a similar problem. If I run user_multiple_role_edit() inside my hook_og_role_grant(), the user does not get added to the group and they are not granted a role.

RoySegall’s picture

OK, i tried to reproduce this but i couldn't. I created a new roll and i added OG to two users(demo and admin) but i didn't got any notices. Try to heck the version of OG depended modules: entity, entity reference & prepopulated etc. etc.