Tuesday, August 8, 2017

Get all terms from the vocabulary

To get all terms from the specific vocabulary use below snippets

$vid = 'name_of_vocabulary';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
 $term_data[] = array(
  "id" => $term->tid,
  "name" => $term->name
 );
}