TermDelete.php in Taxonomy Delete 8
File
src/TermDelete.php
View source
<?php
namespace Drupal\taxonomy_delete;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class TermDelete {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
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);
}
}