public function SubTreeController::json in Taxonomy Manager 8
Same name and namespace in other branches
- 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'
File
- src/
Controller/ SubTreeController.php, line 50
Class
- SubTreeController
- Exposes a list of terms to any JS library via JSON.
Namespace
Drupal\taxonomy_manager\ControllerCode
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);
}