You are here

protected function VisitorsBlock::_showPublishedNodes in Visitors 8.2

Display published nodes count to visitors block.

1 call to VisitorsBlock::_showPublishedNodes()
VisitorsBlock::build in src/Plugin/Block/VisitorsBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/VisitorsBlock.php, line 125
Contains \Drupal\visitors\Plugin\Block\VisitorsBlock.

Class

VisitorsBlock
Provides a 'Visitors' block.

Namespace

Drupal\visitors\Plugin\Block

Code

protected function _showPublishedNodes() {
  if ($this->config
    ->get('show_published_nodes')) {
    $query = \Drupal::database()
      ->select('node', 'n');
    $query
      ->innerJoin('node_field_data', 'nfd', 'n.nid = nfd.nid');
    $query
      ->addExpression('COUNT(*)');
    $query
      ->condition('nfd.status', '1', '=');
    $nodes = $query
      ->execute()
      ->fetchField();
    $this->items[] = t('Published Nodes: %nodes', array(
      '%nodes' => $nodes,
    ));
  }
}