function _term_reference_tree_get_parent in Taxonomy Term Reference Tree Widget 8
Same name and namespace in other branches
- 7.2 term_reference_tree.module \_term_reference_tree_get_parent()
- 7 term_reference_tree.module \_term_reference_tree_get_parent()
Helper function to get the parent of tid.
Parameters
int $tid: The term id.
Return value
int Parent term id or 0.
1 call to _term_reference_tree_get_parent()
- theme_term_tree_list in ./
term_reference_tree.module - Themes the term tree display (as opposed to the select widget).
File
- ./
term_reference_tree.module, line 457
Code
function _term_reference_tree_get_parent($tid) {
$query = "SELECT p.parent_target_id FROM {taxonomy_term__parent} p WHERE p.entity_id = :tid";
$from = 0;
$count = 1;
$args = [
':tid' => $tid,
];
$database = \Drupal::database();
$result = $database
->queryRange($query, $from, $count, $args);
$parent_tid = 0;
foreach ($result as $term) {
$parent_tid = $term->parent_target_id;
}
return $parent_tid;
}