I want to remove all the terms from a vocab but not delete the vocab itself.
I can do it on the database, but Id rather use the api if available in D8.
$existingTerms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('mycustomvocab');
foreach ($existingTerms as $existingTerm) {
// Delete vocabulary term *** This function is not available in D8 ***
taxonomy_term_delete($existingTerm->tid);
// Delete vocabulary - *** Not what is required ***
/*
$vocab = Vocabulary::load($existingTerm->vid);
if (!is_null($vocab)) {
$vocab->delete();
}
*/
}
This is how Im doing it at the moment until I find a better solution
db_query("DELETE FROM {taxonomy_term_hierarchy} WHERE `tid` IN (SELECT tid FROM {taxonomy_term_data} WHERE `vid` = :ctype)", array(':ctype' => 'mycustomvocab'));
db_query("DELETE FROM {taxonomy_term_field_data} WHERE `vid` = :ctype", array(':ctype' => 'mycustomvocab'));
db_query("DELETE FROM {taxonomy_term_data} WHERE `vid` = :ctype", array(':ctype' => 'mycustomvocab'));