TermStorage::loadChildren

public TermStorage::loadChildren($tid, $vid = NULL)

Finds all children of a term ID.

Parameters

int $tid: Term ID to retrieve parents for.

string $vid: An optional vocabulary ID to restrict the child search.

Return value

\Drupal\taxonomy\TermInterface[] An array of term objects that are the children of the term $tid.

Overrides TermStorageInterface::loadChildren

File

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

Class

TermStorage
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

Code

public function loadChildren($tid, $vid = NULL) {
  if (!isset($this->children[$tid])) {
    $children = array();
    $query = $this->database->select('taxonomy_term_field_data', 't');
    $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
    $query->addField('t', 'tid');
    $query->condition('h.parent', $tid);
    if ($vid) {
      $query->condition('t.vid', $vid);
    }
    $query->condition('t.default_langcode', 1);
    $query->addTag('term_access');
    $query->orderBy('t.weight');
    $query->orderBy('t.name');
    if ($ids = $query->execute()->fetchCol()) {
      $children = $this->loadMultiple($ids);
    }
    $this->children[$tid] = $children;
  }
  return $this->children[$tid];
}
doc_Drupal
2016-10-29 09:47:22
Comments
Leave a Comment

Please login to continue.