Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
At group creation I want the creator to be able to choose how new members can join. I added a list field with three values to the group node content type:
- 'anyone' - anyone can join
- 'request' - users can request membership, but group admins must approve
- 'invite' - invitation only
I am currently checking this field's value in a hook_og_user_access_alter and setting the relevant permissions accordingly. I don't want group administrators to have the ability to affect all roles and permissions for their group.
Is there a better place to alter this permission? Perhaps one that would not get checked as often as og_user_access?
/**
* Implements hook_og_user_access_alter().
*
*/
function mash_groups_og_user_access_alter(&$perm, $context) {
$group = $context['group'];
$memberships_opts = $group->field_membership_options[LANGUAGE_NONE][0]['value'];
switch($memberships_opts) {
case 'anyone':
$perm['subscribe'] = FALSE;
$perm['subscribe without approval'] = TRUE;
break;
case 'request':
$perm['subscribe'] = TRUE;
$perm['subscribe without approval'] = FALSE;
break;
case 'invite':
default:
$perm['subscribe'] = FALSE;
$perm['subscribe without approval'] = FALSE;
break;
}
}