function _tft_get_parent_tid in Taxonomy File Tree 8
Same name and namespace in other branches
- 3.x tft.module \_tft_get_parent_tid()
Get the parent tid based on a tid.
Parameters
int $tid: The taxonomy term tid.
Return value
int The parent tid or 0 if there's no parent. Will return -1 if the tid is null or 0.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
2 calls to _tft_get_parent_tid()
- TFTController::ajaxGetFolder in src/Controller/ TFTController.php 
- Returns folder.
- TFTController::get_folder_operation_links in src/Controller/ TFTController.php 
- Return an <ul> with links for the current folder.
File
- ./tft.module, line 127 
- Contains tft.module.
Code
function _tft_get_parent_tid($tid, $gid = NULL) {
  static $cache = [];
  if (!(int) $tid) {
    return -1;
  }
  if (isset($cache[$tid])) {
    return $cache[$tid];
  }
  /** @var \Drupal\taxonomy\TermStorage $storage */
  $storage = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term');
  $result = $storage
    ->loadParents($tid);
  $result = reset($result);
  $cache[$tid] = empty($result) ? -1 : $result
    ->id();
  return (int) $cache[$tid];
}