You are here

public static function TaxonomyManagerTree::getNestedListJsonArray in Taxonomy Manager 8

Same name and namespace in other branches
  1. 2.0.x src/Element/TaxonomyManagerTree.php \Drupal\taxonomy_manager\Element\TaxonomyManagerTree::getNestedListJsonArray()

Function that generates the nested list for the JSON array structure.

2 calls to TaxonomyManagerTree::getNestedListJsonArray()
SubTreeController::json in src/Controller/SubTreeController.php
JSON callback for subtree.
TaxonomyManagerTree::processTree in src/Element/TaxonomyManagerTree.php

File

src/Element/TaxonomyManagerTree.php, line 165

Class

TaxonomyManagerTree
Taxonomy Manager Tree Form Element.

Namespace

Drupal\taxonomy_manager\Element

Code

public static function getNestedListJsonArray($terms) {
  $items = [];
  if (!empty($terms)) {
    foreach ($terms as $term) {
      $item = [
        'title' => Html::escape($term
          ->getName()),
        'key' => $term
          ->id(),
      ];
      if (isset($term->children) || TaxonomyManagerTree::getChildCount($term
        ->id()) >= 1) {

        // If the given terms array is nested, directly process the terms.
        if (isset($term->children)) {
          $item['children'] = TaxonomyManagerTree::getNestedListJsonArray($term->children);
        }
        else {
          $item['lazy'] = TRUE;
        }
      }
      $items[] = $item;
    }
  }
  return $items;
}