Code snippet that can be used to load a list of taxonomy terms in Drupal 8.
<?php
namespace Drupal\mymodule\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Class MyModuleController
* @package Drupal\mymodule\Controller
*/
class MyModuleController extends ControllerBase
{
/**
* @return array
*/
public function index()
{
$vocabulary_name = 'tags';
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vocabulary_name);
$tids = $query->execute();
$terms = Term::loadMultiple($tids);
$output = '<ul>';
foreach ($terms as $term) {
$name = $term->getName();;
$url = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
$link = Link::fromTextAndUrl($name, $url);
$link = $link->toRenderable();
$output .= '<li>' . render($link) . '</li>';
}
$output .= '</ul>';
return array(
'#type' => 'markup',
'#markup' => $output
);
}
}