You are here

function og_entity_delete in Organic groups 7

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

Implements hook_entity_delete().

Delete group membership of deleted entity.

File

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

Code

function og_entity_delete($entity, $type) {
  if (!empty($entity->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE])) {
    list($id) = entity_extract_ids($type, $entity);
    foreach ($entity->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE] as $item) {

      // If the group is already deleted, all the group memberships were already
      // deleted.
      if ($group_membership = og_get_group_membership($item['gid'], $type, $id)) {
        $group_membership
          ->delete();
      }
    }
  }
}