public function TermStorage::loadParents in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::loadParents()
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 105
Class
- TermStorage
- Defines a Controller class for taxonomy terms.
Namespace
Drupal\taxonomyCode
public function loadParents($tid) {
$terms = [];
/** @var \Drupal\taxonomy\TermInterface $term */
if ($tid && ($term = $this
->load($tid))) {
foreach ($this
->getParents($term) as $id => $parent) {
// This method currently doesn't return the <root> parent.
// @see https://www.drupal.org/node/2019905
if (!empty($id)) {
$terms[$id] = $parent;
}
}
}
return $terms;
}