function taxonomy_term_delete
taxonomy_term_delete($tid)
Delete a term.
Parameters
$tid: The term ID.
Return value
Status constant indicating deletion.
File
- modules/taxonomy/taxonomy.module, line 706
- Enables the organization of content into categories.
Code
function taxonomy_term_delete($tid) { $transaction = db_transaction(); try { $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; } } } if ($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); module_invoke_all('taxonomy_term_delete', $term); module_invoke_all('entity_delete', $term, 'taxonomy_term'); taxonomy_terms_static_reset(); } } $tids = $orphans; } return SAVED_DELETED; } catch (Exception $e) { $transaction->rollback(); watchdog_exception('taxonomy', $e); throw $e; } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/function/taxonomy_term_delete/7.x