- if (!isset($this->children[$tid])) {
- $children = [];
- $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('taxonomy_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];
+ /** @var \Drupal\taxonomy\TermInterface $term */
+ return (!empty($tid) && $term = $this->load($tid)) ? $this->getChildren($term) : [];
+ }
+
+ /**
+ * Returns all children terms of this term.
+ *
+ * @return \Drupal\taxonomy\TermInterface[]
+ * A list of children taxonomy term entities keyed by term ID.
+ *
+ * @internal
+ * @todo Refactor away when TreeInterface is introduced.
+ */
+ public function getChildren(TermInterface $term) {
+ $query = \Drupal::entityQuery('taxonomy_term')
+ ->condition('parent', $term->id());
+ return static::loadMultiple($query->execute());