You are here

public function StatisticsPopularBlock::build in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php \Drupal\statistics\Plugin\Block\StatisticsPopularBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php, line 86
Contains \Drupal\statistics\Plugin\Block\StatisticsPopularBlock.

Class

StatisticsPopularBlock
Provides a 'Popular content' block.

Namespace

Drupal\statistics\Plugin\Block

Code

public function build() {
  $content = array();
  if ($this->configuration['top_day_num'] > 0) {
    $result = statistics_title_list('daycount', $this->configuration['top_day_num']);
    if ($result) {
      $content['top_day'] = node_title_list($result, $this
        ->t("Today's:"));
      $content['top_day']['#suffix'] = '<br />';
    }
  }
  if ($this->configuration['top_all_num'] > 0) {
    $result = statistics_title_list('totalcount', $this->configuration['top_all_num']);
    if ($result) {
      $content['top_all'] = node_title_list($result, $this
        ->t('All time:'));
      $content['top_all']['#suffix'] = '<br />';
    }
  }
  if ($this->configuration['top_last_num'] > 0) {
    $result = statistics_title_list('timestamp', $this->configuration['top_last_num']);
    $content['top_last'] = node_title_list($result, $this
      ->t('Last viewed:'));
    $content['top_last']['#suffix'] = '<br />';
  }
  return $content;
}