class TermDelete in Taxonomy Delete 8
Class TermDelete.
@package Drupal\taxonomy_delete
Hierarchy
- class \Drupal\taxonomy_delete\TermDelete
Expanded class hierarchy of TermDelete
1 string reference to 'TermDelete'
1 service uses TermDelete
File
- src/
TermDelete.php, line 11
Namespace
Drupal\taxonomy_deleteView source
class TermDelete {
/**
* Drupal\Core\Entity\EntityTypeManagerInterface definition.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Use core services object.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Delete terms by Vocabulary.
*
* @param string $vid
* The Vocabulary from which the Terms needs to be deleted.
*
* @return array
* An array of terms which gets deleted.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TermDelete:: |
protected | property | Drupal\Core\Entity\EntityTypeManagerInterface definition. | |
TermDelete:: |
public | function | Delete terms by Vocabulary. | |
TermDelete:: |
public | function | Use core services object. |