You are here

public function GroupTypeController::delete in Group 7

Delete a group type.

Overrides EntityAPIControllerExportable::delete

See also

EntityAPIController::delete()

File

classes/group_type.controller.inc, line 17
Defines the Entity API CRUD class for group types.

Class

GroupTypeController
Controller for group type entities.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  $gids = array();
  foreach (group_types($ids) as $group_type) {

    // If an entity is deleted while it was flagged as ENTITY_IN_CODE, it
    // means the entity was either reverted or really deleted. By checking
    // for the 'is_rebuild' property, we know it was deleted from within
    // _entity_defaults_rebuild() which only deletes the entity if the
    // default it came from is no longer available. In any other case, we
    // are dealing with a revert or a manual deletion which will only result
    // in the entity being rebuilt upon next cache clear.
    $entity_in_code = entity_has_status('group_type', $group_type, ENTITY_IN_CODE);
    $entity_rebuilt = !empty($group_type->is_rebuild);

    // Set this on the group type so other modules can use it.
    $group_type->is_revert = $entity_in_code && !$entity_rebuilt;

    // Clean up local roles before deletion.
    $group_type->is_deleted = TRUE;
    $group_type
      ->removeRoles();

    // Gather the group ids of all groups of the deleted type.
    if (!$group_type->is_revert) {
      $groups = group_load_by_type($group_type->name);
      $gids = array_merge($gids, array_keys($groups));
    }

    // Add Internationalization module support.
    if (module_exists('i18n_string')) {
      i18n_string_object_remove('group_type', $group_type);
    }
  }

  // Delete all groups of the group types that weren't being reverted.
  if (!empty($gids)) {
    group_delete_multiple($gids);
  }

  // Delete the group types after setting our flags so those flags are still
  // being passed on to other modules implementing hook_group_type_delete().
  parent::delete($ids, $transaction);

  // Rebuild the menu cache so the group/add page works.
  menu_rebuild();
}