function TermStorage::loadParents

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::loadParents()
  2. 8.9.x core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::loadParents()
  3. 10 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::loadParents()

Overrides TermStorageInterface::loadParents

File

core/modules/taxonomy/src/TermStorage.php, line 93

Class

TermStorage
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.