function og_roles_override in Organic groups 7.2
Same name and namespace in other branches
- 7 og.module \og_roles_override()
Create new roles, based on the default roles and permissions.
Parameters
$group_type: The group type.
$bundle: The bundle type.
$gid: The group ID.
Return value
The newly created roles keyed by role ID and role name as the value. Or FALSE if no roles were created.
3 calls to og_roles_override()
- og_entity_insert in ./
og.module - Implements hook_entity_insert().
- og_entity_update in ./
og.module - Implements hook_entity_update().
- og_field_create_instance in ./
og.module - Implements hook_field_create_instance().
File
- ./
og.module, line 3028 - Enable users to create and manage groups with roles and permissions.
Code
function og_roles_override($group_type, $bundle, $gid) {
// Check if roles aren't already overridden. We can't use
// og_is_group_default_access() as the field is already set, so we
// check to see if there are new roles in the database by setting
// "force group" parameter to TRUE.
if (og_roles($group_type, $bundle, $gid, TRUE)) {
return;
}
$rids = array();
if ($gid) {
// Copy roles from a specific group
$og_roles = og_roles($group_type, $bundle);
$perms = og_role_permissions($og_roles);
}
else {
// Copy the global default roles
$og_roles = og_get_default_roles();
$perms = og_get_default_permissions();
}
foreach ($og_roles as $rid => $name) {
$role = og_role_create($name, $group_type, $gid, $bundle);
og_role_save($role);
$rids[$role->rid] = $role->name;
og_role_change_permissions($role->rid, $perms[$rid]);
// Remap the default roles, to the newely created ones.
db_update('og_users_roles')
->fields(array(
'rid' => $role->rid,
))
->condition('rid', $rid)
->condition('group_type', $group_type)
->condition('gid', $gid)
->execute();
}
return $rids;
}