You are here

public function TermStorage::nodeCount in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::nodeCount()
  2. 9 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::nodeCount()

Count the number of nodes in a given vocabulary ID.

Parameters

string $vid: Vocabulary ID to retrieve terms for.

Return value

int A count of the nodes in a given vocabulary ID.

Overrides TermStorageInterface::nodeCount

File

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

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