📜  Drupal 9 循环术语对象以检索术语数据(id、名称、uuid) - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:43.900000             🧑  作者: Mango

代码示例1
// Get an array of term objects for the given vocabulary
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'my_vocabulary_machine_name']);


if (!empty($terms)) {

  foreach ($terms as $term) {
    //Only return comments that "published" status.
    if ($term->status->value == 1) {
      // These assignments show how to
      // get the term's id, name, and uuid.
      $terms_array[] = [
        'term_tid' => $term->id(),
        'term_name' => $term->name->value,
        'term_uuid' => $term->uuid->value,
      ];
    }
  }

}