You are here

function og_entity_update in Organic groups 7.2

Same name and namespace in other branches
  1. 8 og.module \og_entity_update()

Implements hook_entity_update().

File

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

Code

function og_entity_update($entity, $entity_type) {
  if (!og_is_group($entity_type, $entity)) {
    return;
  }
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  if (!empty($entity->uid) && !og_is_member($entity_type, $id, 'user', $entity->uid, array())) {

    // Subscribe the group manager, in case the owner changed.
    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);
      }
    }
  }
  $original_entity = isset($entity->original) ? $entity->original : NULL;
  $property = OG_DEFAULT_ACCESS_FIELD;
  if (!empty($entity->{$property}) && isset($original_entity->{$property}) && $entity->{$property} != $original_entity->{$property}) {
    if (!og_is_group_default_access($entity_type, $entity)) {

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

      // Delete overridden roles.
      og_delete_user_roles_by_group($entity_type, $entity);
    }
  }
}