public TermStorage::loadChildren($tid, $vid = NULL)
Finds all children of a term ID.
Parameters
int $tid: Term ID to retrieve parents for.
string $vid: An optional vocabulary ID to restrict the child search.
Return value
\Drupal\taxonomy\TermInterface[] An array of term objects that are the children of the term $tid.
Overrides TermStorageInterface::loadChildren
File
- core/modules/taxonomy/src/TermStorage.php, line 170
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 19 20 21 | public function loadChildren( $tid , $vid = NULL) { if (!isset( $this ->children[ $tid ])) { $children = array (); $query = $this ->database->select( 'taxonomy_term_field_data' , 't' ); $query ->join( 'taxonomy_term_hierarchy' , 'h' , 'h.tid = t.tid' ); $query ->addField( 't' , 'tid' ); $query ->condition( 'h.parent' , $tid ); if ( $vid ) { $query ->condition( 't.vid' , $vid ); } $query ->condition( 't.default_langcode' , 1); $query ->addTag( 'term_access' ); $query ->orderBy( 't.weight' ); $query ->orderBy( 't.name' ); if ( $ids = $query ->execute()->fetchCol()) { $children = $this ->loadMultiple( $ids ); } $this ->children[ $tid ] = $children ; } return $this ->children[ $tid ]; } |
Please login to continue.