/** * Helper function that generates the nested list for the JSON array structure. */ public static function getNestedListJSONArray($terms) { $items = array(); if (!empty($terms)) { foreach ($terms as $term) { $item = array('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; }