You are here

public static function TermReferenceFancytree::getChildCount in Term Reference Fancytree 8

Same name and namespace in other branches
  1. 8.2 src/Element/TermReferenceFancytree.php \Drupal\term_reference_fancytree\Element\TermReferenceFancytree::getChildCount()

Helper function that returns the number of child terms.

1 call to TermReferenceFancytree::getChildCount()
TermReferenceFancytree::getNestedListJsonArray in src/Element/TermReferenceFancytree.php
Function that generates the nested list for the JSON array structure.

File

src/Element/TermReferenceFancytree.php, line 346

Class

TermReferenceFancytree
Term Reference Tree Form Element.

Namespace

Drupal\term_reference_fancytree\Element

Code

public static function getChildCount($tid) {
  static $tids = [];
  if (!isset($tids[$tid])) {

    /** @var \Drupal\taxonomy\TermInterface $term */
    $term = Term::load($tid);
    $tids[$tid] = count(static::getTermStorage()
      ->loadTree($term
      ->bundle(), $tid, 1));
  }
  return $tids[$tid];
}