/**
  * Returns partial tree for a given path
  */
 function getPartialTree($path, $depth = 0)
 {
     $tree = array();
     $parent = $path[$depth];
     $children = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadChildren($parent->id());
     if (isset($path[++$depth])) {
         $next_term = $path[$depth];
     }
     $index = 0;
     foreach ($children as $child) {
         $child->depth = $depth;
         $child->parents = array(0 => $parent->tid);
         $tree[] = array('title' => $child->getName(), 'key' => $child->id(), 'expanded' => TRUE, 'selected' => TRUE);
         if (isset($next_term) && $child->id() == $next_term->id()) {
             $tree[$index]['children'] = TaxonomyManagerTree::getPartialTree($path, $depth);
         }
         $index++;
     }
     return $tree;
 }