taxonomy_term_delete

Versions
7
taxonomy_term_delete($tid)

Delete a term.

Parameters

$tid The term ID.

Return value

Status constant indicating deletion.

▾ 3 functions call taxonomy_term_delete()

forum_confirm_delete_submit in modules/forum/forum.admin.inc
Implement forms api _submit call. Deletes a forum after confirmation.
taxonomy_term_confirm_delete_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler to delete a term after confirmation.
taxonomy_vocabulary_delete in modules/taxonomy/taxonomy.module
Delete a vocabulary.

Code

modules/taxonomy/taxonomy.module, line 484

<?php
function taxonomy_term_delete($tid) {
  $tids = array($tid);
  while ($tids) {
    $children_tids = $orphans = array();
    foreach ($tids as $tid) {
      // See if any of the term's children are about to be become orphans:
      if ($children = taxonomy_get_children($tid)) {
        foreach ($children as $child) {
          // If the term has multiple parents, we don't delete it.
          $parents = taxonomy_get_parents($child->tid);
          if (count($parents) == 1) {
            $orphans[] = $child->tid;
          }
        }
      }

      $term = taxonomy_term_load($tid);

      db_delete('taxonomy_term_data')
        ->condition('tid', $tid)
        ->execute();
      db_delete('taxonomy_term_hierarchy')
        ->condition('tid', $tid)
        ->execute();

      field_attach_delete('taxonomy_term', $term);
      _taxonomy_clean_field_cache($term);
      module_invoke_all('taxonomy_term_delete', $term);
    }

    $tids = $orphans;
  }

  cache_clear_all();
  taxonomy_terms_static_reset();

  return SAVED_DELETED;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.