Question

I'm trying to show or hide a button based on if a user has permission to post content to a group or not, but I don't seem to be able to call the og_user_access function from my custom module.

I've tried calling it directly while loading the module file:

module_load_include('module', 'og'); 
$allowed = og_user_access('group', $group->nid, 'create resource content');

Doing this crashes the page with no Apache error just a watchdog error of:

Error: Class name must be a valid object or a string in entity_get_controller() (line 8066 of /data/home/rsdev/www/content/lnsres.rsdev.ca/web/includes/common.inc).

I've also tried using module_invoke like so:

$allowed = module_invoke('og', 'og_user_access', 'group', $group->nid, 'create resource content');

Calling the module like this doesn't crash the page, but it also doesn't return anything and if I add some dpm() calls in the contrib module function I notice it's not even being called. Doing some reading about module_invoke appears like it's mostly used to call hooks, which I don't think og_user_access is, so I'm not sure if that's even the correct path to take.

How should I check group permissions in OG from my custom module's code ?

EDIT: This is not a duplicate of Display data basing on the group permission because I'm not trying to use a permission I created. Also the only answer in that question doesn't work for me because as I explained, I can't call og_user_access without an error.

Was it helpful?

Solution

if your group entity is a node which I'm guessing it should be change your code to:

$gid // your group's node id.
$allowed = og_user_access('node', $gid, 'create resource content');
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top