public TermStorage::loadParents($tid)
Finds all parents of a given term ID.
Parameters
int $tid: Term ID to retrieve parents for.
Return value
\Drupal\taxonomy\TermInterface[] An array of term objects which are the parents of the term $tid.
Overrides TermStorageInterface::loadParents
File
- core/modules/taxonomy/src/TermStorage.php, line 121
Class
- TermStorage
- Defines a Controller class for taxonomy terms.
Namespace
Drupal\taxonomy
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public function loadParents( $tid ) { if (!isset( $this ->parents[ $tid ])) { $parents = array (); $query = $this ->database->select( 'taxonomy_term_field_data' , 't' ); $query ->join( 'taxonomy_term_hierarchy' , 'h' , 'h.parent = t.tid' ); $query ->addField( 't' , 'tid' ); $query ->condition( 'h.tid' , $tid ); $query ->condition( 't.default_langcode' , 1); $query ->addTag( 'term_access' ); $query ->orderBy( 't.weight' ); $query ->orderBy( 't.name' ); if ( $ids = $query ->execute()->fetchCol()) { $parents = $this ->loadMultiple( $ids ); } $this ->parents[ $tid ] = $parents ; } return $this ->parents[ $tid ]; } |
Please login to continue.