You are here

function _tft_folder_tree in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x tft.module \_tft_folder_tree()

Returns TFT folder tree.

2 calls to _tft_folder_tree()
ReorderFolderForm::buildForm in src/Form/ReorderFolderForm.php
Form constructor.
tft_form_alter in ./tft.module
Implements hook_form_alter().

File

./tft.module, line 302
Contains tft.module.

Code

function _tft_folder_tree($tid = 0, $inclusive = FALSE) {
  $folders = [];
  $content = _tft_folder_content($tid);
  foreach ($content as $item) {
    if ($item['type'] == 'term' && _tft_term_access($item['id'])) {
      $folders[$item['id']]['weight'] = isset($item['weight']) ? $item['weight'] : 0;
      $folders[$item['id']]['parent'] = $tid ? $tid : 0;
      $folders[$item['id']]['type'] = $item['type'];
      $folders[$item['id']]['tid'] = $item['id'];
      $folders[$item['id']]['name'] = $item['name'];
      if ($child_terms = _tft_folder_tree($item['id'])) {
        $folders[$item['id']]['children'] = $child_terms;
      }
    }
  }
  if ($inclusive) {
    if ($tid == 0) {
      $name = t("Root");
    }
    else {
      $name = Term::load($tid)
        ->getName();
    }
    $folders = [
      $tid => [
        'name' => $name,
        'tid' => $tid,
        'weight' => 0,
        'parent' => 0,
        'type' => 'term',
        'children' => $folders,
      ],
    ];
  }
  return $folders;
}