Answers for "Drupal 9 loop term objects to retrieve term data (id, name, uuid)"

PHP
0

Drupal 9 loop term objects to retrieve term data (id, name, uuid)

// 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,
      ];
    }
  }

}
Posted by: Guest on January-04-2022

Browse Popular Code Answers by Language