1

I have created a custom group role with some custom permissions and I am trying to find a way to allocate this role to group members by default. Ideally I would like every member of every group to be allocated this role, and be able to remove this role from a user if I no longer want the particular user to have my custom permissions.

I believe OG User Roles had this functionality and user roles were put into core organic groups for 7 but I am not sure if this default roles functionality was also implemented?

2
  • OG user roles has this functionality.
    – Rishi
    Jun 25, 2012 at 7:25
  • I am using Drupal 7 and User Roles is only for 6, as I said above, the role functionality got added into core Organic Groups but I am unsure of the default role functionality.
    – Teegan
    Jun 25, 2012 at 7:28

2 Answers 2

0

I found a solution to this by using og_role_grant within hook_og_membership_insert and hard coding my role in there. This works by granting the role to a user who has just been added as a member of a group. If I had more time I would create myself a form in the backend so it wouldn't be hard coded but for now this seems to work fine.

function MODULENAME_og_membership_insert(OgMembership $og_membership) {

  if('user' == $og_membership->entity_type && is_numeric($og_membership->etid)){
    $roles = og_roles($og_membership->gid);
    foreach($roles as $key => $value){
      if ('ROLE_NAME' == $value) {
        og_role_grant($og_membership->gid, $og_membership->etid, $key);
      }
    }
  }
}
0

Yep, this is not provided by default, i'd spen hour understanding that by default users have no role in group where they was added. Maybe i cant find that setting... But seems like for now using hook_og_membership_insert is only solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.