You are here

public function TermStorage::loadParents in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::loadParents()
  2. 10 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 106

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