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

tarluk’s picture

ok 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) {

tarluk’s picture

Ok 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.

Josh Benner’s picture

Title: extra u in variable defenition line 102 og_default_roles.module » Users not receiving roles when created and added to group by admin in one action
Assigned: Unassigned » Josh Benner
Status: Active » Postponed (maintainer needs more info)

Okay, a few issues here:

  1. Variable names in that file are correct, but it does seem at first glance as a typo. I'll update them to be a little more obvious so we don't suspect a mistake there in the future.
  2. When I test locally, the logs are logging group and role names, not the ID numbers. I'm not sure, but perhaps this is related to the use of array_diff_key() that I've resolved in the next release.
  3. The main issue here is the assignment of roles to users who are joining groups at creation, either by registration form or by admin action. I'll investigate.
Josh Benner’s picture

Version: 5.x-1.0 » 5.x-1.1
Status: Postponed (maintainer needs more info) » Closed (won't fix)

Okay, 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.