there is an extra u in line 102 of the module file
/**
* Implementation of hook_og()
*/
function og_default_roles_og($op, $nid, $uid, $args = array()) {
switch ($op) {
case 'user insert':
$roles = og_default_roles_group_grants($nid);
if ($args['is_active']) {
$account = user_load(array('uid' => $uid));
$uroles = array_keys($account->roles);
$needs = array();
foreach ($roles as $rid=>$rname) {
if (!in_array($rid, $uroles)) {
$needs[$rid] = $rname;
}
}
if ($needs) {
$edit['roles'] = $account->roles + $needs;
user_save($account, $edit);
$group = node_load($nid);
$vars = array(
'!user' => $account->name,
'!group' => $group->title,
'!roles' => implode(', ', $needs),
);
watchdog('og_default_roles', t('!user was granted these roles for joining !group: !roles', $vars));
cache_clear_all($account->uid.':', 'cache_menu', TRUE);
}
}
break;
variable is defined as $uroles and called as $roles
Comments
Comment #1
tarluk commentedok slightly wrong there there is a lack of a u on line 104, line should read
foreach ($uroles as $rid=>$rname) {
not
foreach ($roles as $rid=>$rname) {
Comment #2
tarluk commentedOk after playing with the file and trying different combinations of variables to see if I can get it to work and I don't know if it is as simple as a missing u.
with the original code I get the error
warning: Invalid argument supplied for foreach() in /xxxxxxxxxx/modules/og_default_roles/og_default_roles.module on line 104.
This is both if I create a new user as admin and if I create a new user through the front page. creating a new user through admin the user does not gain the roles that it should from default roles, through the front page it does. however this latter part may be due to the front page being locked to admin needing to give permission to join
Also if I join a group after user creation then addition of the default role works perfectly. so it may well be something to do with the uid not being created until after og_default_roles has tried to give it a role.
If I change the variable sited above I get no error message but when I look to see if any role has been assigned none has, however in the log message from og_default_roles there is an assignment of roles, but the assignment is to the role id number not the role itself message is as follows
[user] was granted these roles for joining [group]: 2 - where 2 is the role node number for the role being assigned for the group
which realy isn't what is needed.
Comment #3
Josh Benner commentedOkay, a few issues here:
Comment #4
Josh Benner commentedOkay, this occurs because the OG hook is called before the user creation completes. og_default_roles is actually assigning the roles properly, but Drupal is overriding this when you create a user and assign group membership at the same time.
This is a limitation of the og hook, and not of this module. I'm open to any ideas on how to address it. Until then, nothing will be done on this issue.