In trying to get my module working with OG User Roles, I was forced to make a change to og_user_roles_all_roles(). Whilst this wouldn't be too bad, as there are already dozens of special cases in there for other modules, it strikes me as a better solution to expose a hook in that function so that other modules can provide their own logic without your having to change the OG User Roles code.

I've attached a patch which does this.

Comments

somebodysysop’s picture

Assigned: Unassigned » somebodysysop
Category: bug » feature
Status: Active » Needs review

Seems like a pretty good idea. Let me see if I understand:

1. The hook would be hook_og_user_roles_gid as in "YourModuleName_og_user_roles_gid".
2. hook_og_user_roles_gid would simply return a single Group Node ID which should represent the current group context that a user is in when it's invoked.
3. The module_invoke('og_user_roles_gid') is ran at the end of the $gid if statement in og_user_roles_all_roles(), that is, if the OG group context is not present, then we try to figure it out, and we will use your's if your module presents one.

Is this correct?

If so, what does hook_og_user_roles_gid look like? I know the Return Value is a single Group Node ID. But, are there an input Parameters?

Thanks for the patch and the work!

dmhouse’s picture

An implementation of hook_og_user_roles_gid takes no input parameters, and should return the current group context's gid, as you suggest. Here's how I use it in my module:

function filenode_og_user_roles_gid() {
  if (arg(0) == 'og' && arg(1) == 'files') {
    if (is_numeric(arg(2))) {
      $gid = arg(2);
    } elseif (is_numeric(arg(3))) { // E.g. og/files/create-subdir/104
      $gid = arg(3);
    }
  }
  if ($gid) return $gid;
}
somebodysysop’s picture

StatusFileSize
new1.19 KB

OK, then, apply this patch against the 2.4 release and see it does the trick.

dmhouse’s picture

Looks good.

somebodysysop’s picture

Status: Needs review » Fixed

I'll take that as a yes.

Anonymous’s picture

Status: Fixed » Closed (fixed)