You are here

function og_entity_insert in Organic groups 7.2

Same name and namespace in other branches
  1. 8 og.module \og_entity_insert()
  2. 7 og.module \og_entity_insert()

Implements hook_entity_insert().

File

./og.module, line 854
Enable users to create and manage groups with roles and permissions.

Code

function og_entity_insert($entity, $entity_type) {
  if (!og_is_group($entity_type, $entity)) {
    return;
  }
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  if (!empty($entity->uid)) {

    // Subscribe the group manager.
    og_group($entity_type, $id, array(
      'entity' => $entity->uid,
    ));

    // Assign roles to group manager.
    $name = 'og_group_manager_default_rids_' . $entity_type . '_' . $bundle;
    if ($rids = variable_get($name)) {
      foreach ($rids as $rid) {
        og_role_grant($entity_type, $id, $entity->uid, $rid);
      }
    }
  }
  if (!og_is_group_default_access($entity_type, $entity)) {

    // Override default roles.
    og_roles_override($entity_type, $bundle, $id);
  }
}