public TermStorage::loadAllParents($tid)
Finds all ancestors of a given term ID.
Parameters
int $tid: Term ID to retrieve ancestors for.
Return value
\Drupal\taxonomy\TermInterface[] An array of term objects which are the ancestors of the term $tid.
Overrides TermStorageInterface::loadAllParents
File
- core/modules/taxonomy/src/TermStorage.php, line 143
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 22 23 | public function loadAllParents( $tid ) { if (!isset( $this ->parentsAll[ $tid ])) { $parents = array (); if ( $term = $this ->load( $tid )) { $parents [ $term ->id()] = $term ; $terms_to_search [] = $term ->id(); while ( $tid = array_shift ( $terms_to_search )) { if ( $new_parents = $this ->loadParents( $tid )) { foreach ( $new_parents as $new_parent ) { if (!isset( $parents [ $new_parent ->id()])) { $parents [ $new_parent ->id()] = $new_parent ; $terms_to_search [] = $new_parent ->id(); } } } } } $this ->parentsAll[ $tid ] = $parents ; } return $this ->parentsAll[ $tid ]; } |
Please login to continue.