function TermStorage::nodeCount

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

Overrides TermStorageInterface::nodeCount

File

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

Class

TermStorage
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

Code

public function nodeCount($vid) {
    $query = $this->database
        ->select('taxonomy_index', 'ti');
    $query->addExpression('COUNT(DISTINCT [ti].[nid])');
    $query->leftJoin($this->getBaseTable(), 'td', '[ti].[tid] = [td].[tid]');
    $query->condition('td.vid', $vid);
    $query->addTag('vocabulary_node_count');
    return $query->execute()
        ->fetchField();
}

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