public function TermDelete::deleteTermByVid in Taxonomy Delete 8
Delete terms by Vocabulary.
Parameters
string $vid: The Vocabulary from which the Terms needs to be deleted.
Return value
array An array of terms which gets deleted.
File
- src/
TermDelete.php, line 36
Class
- TermDelete
- Class TermDelete.
Namespace
Drupal\taxonomy_deleteCode
public function deleteTermByVid($vid) {
$terms = [];
$controller = $this->entityTypeManager
->getStorage('taxonomy_term');
$tree = $controller
->loadTree($vid);
foreach ($tree as $term) {
$terms[] = $term->tid;
}
$entities = $controller
->loadMultiple($terms);
$controller
->delete($entities);
return count($terms);
}