You are here

public function SubTreeController::json in Taxonomy Manager 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/SubTreeController.php \Drupal\taxonomy_manager\Controller\SubTreeController::json()

JSON callback for subtree.

Return value

\Symfony\Component\HttpFoundation\JsonResponse JSON object with list of terms.

1 string reference to 'SubTreeController::json'
taxonomy_manager.routing.yml in ./taxonomy_manager.routing.yml
taxonomy_manager.routing.yml

File

src/Controller/SubTreeController.php, line 50

Class

SubTreeController
Exposes a list of terms to any JS library via JSON.

Namespace

Drupal\taxonomy_manager\Controller

Code

public function json() {
  $list = [];
  $parent = $this->request
    ->get('parent');
  $term = $this
    ->entityTypeManager()
    ->getStorage('taxonomy_term')
    ->load($parent);
  if ($term) {
    $taxonomy_vocabulary = $this
      ->entityTypeManager()
      ->getStorage('taxonomy_vocabulary')
      ->load($term
      ->getVocabularyId());
    if ($taxonomy_vocabulary) {
      $terms = TaxonomyManagerTree::loadTerms($taxonomy_vocabulary, $parent);
      $list = TaxonomyManagerTree::getNestedListJsonArray($terms);
    }
  }
  return new JsonResponse($list);
}