0

I need to retrieve the rid to assign the 'student' role part of an og group.

I found this post in regards to user roles How do I find the role id from role name?

$rid = array_search('student', user_roles());
og_role_grant('node', $id, $user->uid, $rid);

Is there also a function for og group roles?

0

Found a helpful solution using a db query https://www.hashbangcode.com/article/load-drupal-organic-group-role-name

$roleid = db_query("SELECT rid, name FROM og_role WHERE gid = :gid and name = :name ORDER BY rid",array(':gid' => 14, 'name' => 'student'))->fetchAssoc();

Let me know in case there is any other or better solution, thanks!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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