You are here

function group_entity_delete in Group 7

Same name and namespace in other branches
  1. 8 group.module \group_entity_delete()
  2. 2.0.x group.module \group_entity_delete()

Implements hook_entity_delete().

File

./group.entity.inc, line 715
Contains all Entity API functions for the Group module.

Code

function group_entity_delete($entity, $type) {
  $entity_info = entity_get_info($type);

  // Retrieve the entity id and bundle.
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($type, $entity);

  // Delete group memberships.
  if ($type === 'user') {
    $mids = array_keys(group_membership_load_by_user($entity_id));
    group_membership_delete_multiple($mids);
  }

  // Delete group entity mappings.
  if (!empty($entity_info['group entity']) && !empty($entity->group)) {
    foreach (group_load_multiple((array) $entity->group) as $group) {
      $group
        ->removeEntity($entity_id, $type);
    }
  }
}