Чтобы получить объекты терминов таксономии в Drupal 9 по имени словарного аппарата (vid), вы можете использовать следующие методы:
-
Использование диспетчера типов объектов:
use Drupal\Core\Entity\EntityTypeManagerInterface; / * @var EntityTypeManagerInterface $entityTypeManager */ $entityTypeManager = \Drupal::service('entity_type.manager'); $taxonomyTermStorage = $entityTypeManager->getStorage('taxonomy_term'); $terms = $taxonomyTermStorage->loadTree($vocabulary_machine_name); -
Использование службы хранения терминов таксономии:
use Drupal\taxonomy\TermStorageInterface; / * @var TermStorageInterface $taxonomyTermStorage */ $taxonomyTermStorage = \Drupal::service('entity_type.manager')->getStorage('taxonomy_term'); $terms = $taxonomyTermStorage->loadTree($vocabulary_machine_name); -
Использование запроса сущности:
use Drupal\Core\Entity\Query\QueryFactoryInterface; / * @var QueryFactoryInterface $entityQuery */ $entityQuery = \Drupal::service('entity.query'); $query = $entityQuery->get('taxonomy_term') ->condition('vid', $vocabulary_machine_name); $tids = $query->execute(); $terms = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadMultiple($tids);
Эти методы извлекают объекты терминов таксономии на основе имени словарной машины (vid) в Drupal 9.