You are here

function og_vocab_realtion_delete in OG Vocabulary 7

Delete a relation between a group and a vocabulary and all its OG-vocabs.

Parameters

$entity_type: The entity type is deleted.

$entity_id: The entity ID that is deleted.

1 call to og_vocab_realtion_delete()
og_vocab_entity_delete in ./og_vocab.module
Implements hook_entity_delete().

File

./og_vocab.module, line 778
Give each group its own system controlled vocabularies.

Code

function og_vocab_realtion_delete($entity_type, $entity_id) {
  $vids = array();
  if ($entity_type == 'taxonomy_vocabulary') {
    if (!($relation = og_vocab_relation_get($entity_id))) {
      return;
    }
    $vids[] = $entity_id;
  }
  else {

    // Get the vocabylary ID from the group.
    if (!($relations = og_vocab_relation_get_by_group($entity_type, $entity_id))) {
      return;
    }
    foreach ($relations as $relation) {
      $vids[] = $relation->vid;
    }
  }
  db_delete('og_vocab_relation')
    ->condition('vid', $vids, 'IN')
    ->execute();

  // Get all OG vocabs related to the entity_type, and delete them.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'og_vocab')
    ->propertyCondition('vid', $vids, 'IN')
    ->execute();
  if (empty($result['og_vocab'])) {
    return;
  }
  entity_delete_multiple('og_vocab', array_keys($result['og_vocab']));
}