7 taxonomy.module taxonomy_vocabulary_delete($vid)

Deletes a vocabulary.

This will update all Taxonomy fields so that they don't reference the deleted vocabulary. It also will delete fields that have no remaining vocabulary references. All taxonomy terms of the deleted vocabulary will be deleted as well.


$vid: A vocabulary ID.

Return value

Constant indicating items were deleted.

8 calls to taxonomy_vocabulary_delete()
EntityCrudHookTestCase::testTaxonomyVocabularyHooks in modules/simpletest/tests/entity_crud_hook_test.test
Tests hook invocations for CRUD operations on taxonomy vocabularies.
TaxonomyTermFieldMultipleVocabularyTestCase::testTaxonomyTermFieldMultipleVocabularies in modules/taxonomy/taxonomy.test
Tests term reference field and widget with multiple vocabularies.
TaxonomyTermFieldTestCase::testTaxonomyTermFieldWidgets in modules/taxonomy/taxonomy.test
Test widgets.
TaxonomyVocabularyFunctionalTest::testTaxonomyAdminNoVocabularies in modules/taxonomy/taxonomy.test
Test the vocabulary overview with no vocabularies.
TaxonomyVocabularyTestCase::testTaxonomyVocabularyDeleteWithTerms in modules/taxonomy/taxonomy.test
Test deleting a taxonomy that contains terms.

... See full list


modules/taxonomy/taxonomy.module, line 472
Enables the organization of content into categories.


function taxonomy_vocabulary_delete($vid) {
  $vocabulary = taxonomy_vocabulary_load($vid);

  $transaction = db_transaction();
  try {
    // Only load terms without a parent, child terms will get deleted too.
    $result = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid = :vid AND th.parent = 0', array(':vid' => $vid))->fetchCol();
    foreach ($result as $tid) {
      ->condition('vid', $vid)

    field_attach_delete_bundle('taxonomy_term', $vocabulary->machine_name);
    module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);
    module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');

    // Load all Taxonomy module fields and delete those which use only this
    // vocabulary.
    $taxonomy_fields = field_read_fields(array('module' => 'taxonomy'));
    foreach ($taxonomy_fields as $field_name => $taxonomy_field) {
      $modified_field = FALSE;
      // Term reference fields may reference terms from more than one
      // vocabulary.
      foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) {
        if ($allowed_value['vocabulary'] == $vocabulary->machine_name) {
          $modified_field = TRUE;
      if ($modified_field) {
        if (empty($taxonomy_field['settings']['allowed_values'])) {
        else {
          // Update the field definition with the new allowed values.


    return SAVED_DELETED;
  catch (Exception $e) {
    watchdog_exception('taxonomy', $e);
    throw $e;