語彙からすべての用語を削除したいが、語彙自体は削除したくない。
データベースでそれを行うことができますが、D8で利用可能な場合はむしろAPIを使用します。
$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();
}
*/
}
これは、私がより良い解決策を見つけるまで、現時点でそれをやっている方法です
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'));