public function TermStorage::loadParents in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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
1 call to TermStorage::loadParents()
- TermStorage::loadAllParents in core/
modules/ taxonomy/ src/ TermStorage.php - Finds all ancestors of a given term ID.
File
- core/
modules/ taxonomy/ src/ TermStorage.php, line 126 - Contains \Drupal\taxonomy\TermStorage.
Class
- TermStorage
- Defines a Controller class for taxonomy terms.
Namespace
Drupal\taxonomyCode
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];
}