diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php index b62a3ab..bebfbed 100644 --- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php @@ -193,19 +193,31 @@ public function build() { return $content; } - protected function nodeTitleList($counts, $title){ + protected function nodeTitleList($counts, $title) { $nodes = $this->entityManager->getStorage('node')->loadMultiple($counts); $items = array(); foreach ($counts as $count) { - $items [] = \Drupal::l($nodes[$count]->getTitle(), $nodes[$count]->urlInfo('canonical')); + // $items [] = \Drupal::l($nodes[$count]->getTitle(), $nodes[$count]->urlInfo('canonical')); + $items [] = array( + '#type' => 'link', + '#title' => $nodes[$count]->getTitle(), + '#url' => $nodes[$count]->urlInfo('canonical'), + '#cache' => array( + 'context' => $nodes[$count]->getCacheContexts(), + 'tags' => $nodes[$count]->getCacheTags(), + ), + ); } return array( '#theme' => 'item_list__node', '#items' => $items, '#title' => $title, - '#cache' => ['tags' => Cache::mergeTags(['node_list'], Cache::buildTags('node', $counts))] + '#cache' => array( + 'context' => 'user.roles', + 'tags' => $this->entityManager->getDefinition('node')->getListCacheTags(), + ), ); } diff --git a/core/modules/statistics/src/StatisticsDatabaseStorage.php b/core/modules/statistics/src/StatisticsDatabaseStorage.php index 0132e2a..b75ad9a 100644 --- a/core/modules/statistics/src/StatisticsDatabaseStorage.php +++ b/core/modules/statistics/src/StatisticsDatabaseStorage.php @@ -61,7 +61,7 @@ public function recordHit($nid) { * {@inheritdoc} */ public function fetchViews($nid) { - // Retrieve an array with both totalcount, daycount and timestamp. + // Retrieve an array, which includes totalcount, daycount, and timestamp. return $this->connection->select('node_counter', 'nc') ->fields('nc', array('totalcount', 'daycount', 'timestamp')) ->condition('nid', $nid, '=')->execute()->fetchAssoc(); @@ -71,10 +71,13 @@ public function fetchViews($nid) { * {@inheritdoc} */ public function fetchAll($order = 'totalcount', $limit = 5) { - return $this->connection->select('node_counter', 'nc') - ->fields('nc', array('nid')) - ->orderBy($order, 'DESC')->range(0, $limit) - ->execute()->fetchCol(); + if (in_array($order, array('totalcount', 'daycount', 'timestamp'))) { + return $this->connection->select('node_counter', 'nc') + ->fields('nc', array('nid')) + ->orderBy($order, 'DESC')->range(0, $limit) + ->execute()->fetchCol(); + } + return FALSE; } /** diff --git a/core/modules/statistics/src/StatisticsStorageInterface.php b/core/modules/statistics/src/StatisticsStorageInterface.php index 64e30ae..2de7e38 100644 --- a/core/modules/statistics/src/StatisticsStorageInterface.php +++ b/core/modules/statistics/src/StatisticsStorageInterface.php @@ -44,8 +44,11 @@ public function fetchViews($nid); /** * Returns the number of times a node has been viewed. * - * @param strign $order - * The column name to order by. + * @param string $order + * The counter name to order by: + * - 'totalcount' The total number of views. + * - 'daycount' The number of views today. + * - 'timestamp' The unix timestamp of the last view. * * @return array * An ordered array of node ids. @@ -64,7 +67,10 @@ public function fetchAll($order = 'totalcount', $limit = 5); public function clean($nid); /** - * Returns if reset is needed. + * A reset is performed daily. + * Returns if 24 hours has passed since the last reset. + * + * @see StatisticsStorageInterface::resetDayCount() To perform the reset. * * @return bool * TRUE if reset is needed.