You are here

function og_test_entity_delete in Organic groups 7.2

Implements hook_entity_delete().

File

tests/og_test.module, line 52
Test module for OG.

Code

function og_test_entity_delete($entity, $type) {
  if (!og_is_group($type, $entity) || $entity->title != 'move') {
    return;
  }

  // The children nodes of the deleted group need another group to be associated
  // with. Using entity field query for getting the NID of another group.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'node')
    ->propertyCondition('nid', $entity->nid, '<>')
    ->execute();
  if (empty($result['node'])) {
    return;
  }
  $nids = array_keys($result['node']);
  $nid = reset($nids);
  $entity->og_orphans = array(
    'move' => array(
      'group_type' => 'node',
      'gid' => $nid,
    ),
  );
}