In Drupal 7 there was taxonomy_vocabulary_delete($vid)
, but this doesn't seem to be there in Drupal 8.
What's the equivalent code for Drupal 8?
I believe I have figured this out. You have to load the vocabulary using the Vocabulary
entity class, then call the delete method on it. So something like this:
Vocabulary::load($vid)->delete();
$tids = \Drupal::entityQuery('taxonomy_term')
->condition('vid', 'tags')
->execute();
$controller = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$entities = $controller->loadMultiple($tids);
$controller->delete($entities);
Or
$vid = 'tags';
$tids = Drupal::entityQuery('taxonomy_term')
->condition('vid', $vid)
->execute();
entity_delete_multiple('taxonomy_term', $tids);
Here is how I did it
$vocabularies = [
'test',
'second_test'
];
foreach ($vocabularies as $vocabulary) {
$vocab = Drupal\taxonomy\Entity\Vocabulary::load($vocabulary);
if ($vocab) {
$vocab->delete();
}
}