diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php index 439d97f..aab210c 100644 --- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php @@ -99,11 +99,11 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function defaultConfiguration() { - return array( + return [ 'top_day_num' => 0, 'top_all_num' => 0, 'top_last_num' => 0 - ); + ]; } /** @@ -134,29 +134,29 @@ protected function blockAccess(AccountInterface $account) { */ public function blockForm($form, FormStateInterface $form_state) { // Popular content block settings. - $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40); - $numbers = array('0' => $this->t('Disabled')) + array_combine($numbers, $numbers); - $form['statistics_block_top_day_num'] = array( + $numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40]; + $numbers = ['0' => $this->t('Disabled')] + array_combine($numbers, $numbers); + $form['statistics_block_top_day_num'] = [ '#type' => 'select', '#title' => $this->t("Number of day's top views to display"), '#default_value' => $this->configuration['top_day_num'], '#options' => $numbers, '#description' => $this->t('How many content items to display in "day" list.'), - ); - $form['statistics_block_top_all_num'] = array( + ]; + $form['statistics_block_top_all_num'] = [ '#type' => 'select', '#title' => $this->t('Number of all time views to display'), '#default_value' => $this->configuration['top_all_num'], '#options' => $numbers, '#description' => $this->t('How many content items to display in "all time" list.'), - ); - $form['statistics_block_top_last_num'] = array( + ]; + $form['statistics_block_top_last_num'] = [ '#type' => 'select', '#title' => $this->t('Number of most recent views to display'), '#default_value' => $this->configuration['top_last_num'], '#options' => $numbers, '#description' => $this->t('How many content items to display in "recently viewed" list.'), - ); + ]; return $form; } @@ -173,7 +173,7 @@ public function blockSubmit($form, FormStateInterface $form_state) { * {@inheritdoc} */ public function build() { - $content = array(); + $content = []; if ($this->day_list) { $content['top_day'] = $this->nodeTitleList($this->day_list, $this->t("Today's:")); @@ -197,39 +197,40 @@ public function build() { * Generates the render array for the block. * * @param array $counts - * An ordered array of node ids. + * An ordered array of node ids. * * @param string $title - * The title for the list. + * The title for the list. * * @return array - * A render array for the list. + * A render array for the list. */ protected function nodeTitleList($counts, $title) { $nodes = $this->entityManager->getStorage('node')->loadMultiple($counts); - $items = array(); + $items = []; foreach ($counts as $count) { - $items [] = array( + $node = $this->entityManager->getTranslationFromContext($nodes[$count]); + $items[] = [ '#type' => 'link', - '#title' => $nodes[$count]->getTitle(), - '#url' => $nodes[$count]->urlInfo('canonical'), - '#cache' => array( - 'context' => $nodes[$count]->getCacheContexts(), - 'tags' => $nodes[$count]->getCacheTags(), - ), - ); + '#title' => $node->getTitle(), + '#url' => $node->urlInfo('canonical'), + '#cache' => [ + 'context' => $node->getCacheContexts(), + 'tags' => $node->getCacheTags(), + ], + ]; } - return array( + return [ '#theme' => 'item_list__node', '#items' => $items, '#title' => $title, - '#cache' => array( - 'context' => 'user.permissions', - 'tags' => $this->entityManager->getDefinition('node')->getListCacheTags(), - ), - ); + '#cache' => [ + 'context' => 'user.permissions', + 'tags' => $this->entityManager->getDefinition('node')->getListCacheTags(), + ], + ]; } } diff --git a/core/modules/statistics/src/StatisticsDatabaseStorage.php b/core/modules/statistics/src/StatisticsDatabaseStorage.php index 296795e..bbbd294 100644 --- a/core/modules/statistics/src/StatisticsDatabaseStorage.php +++ b/core/modules/statistics/src/StatisticsDatabaseStorage.php @@ -29,7 +29,7 @@ class StatisticsDatabaseStorage implements StatisticsStorageInterface { protected $state; /** - * Construct the statistics storage. + * Constructs the statistics storage. * * @param \Drupal\Core\Database\Connection $connection * The database connection for the node view storage. @@ -47,11 +47,11 @@ public function __construct(Connection $connection, StateInterface $state) { public function recordHit($nid) { return (bool) $this->connection->merge('node_counter') ->key('nid', $nid) - ->fields(array( + ->fields([ 'daycount' => 1, 'totalcount' => 1, 'timestamp' => REQUEST_TIME, - )) + ]) ->expression('daycount', 'daycount + 1') ->expression('totalcount', 'totalcount + 1') ->execute(); @@ -63,7 +63,7 @@ public function recordHit($nid) { public function fetchViews($nid) { // Retrieve an array, which includes totalcount, daycount, and timestamp. return $this->connection->select('node_counter', 'nc') - ->fields('nc', array('totalcount', 'daycount', 'timestamp')) + ->fields('nc', ['totalcount', 'daycount', 'timestamp']) ->condition('nid', $nid, '=')->execute()->fetchAssoc(); } @@ -77,7 +77,7 @@ public function fetchAll($order = 'totalcount', $limit = 5) { } return $this->connection->select('node_counter', 'nc') - ->fields('nc', array('nid')) + ->fields('nc', ['nid']) ->orderBy($order, 'DESC')->range(0, $limit) ->execute()->fetchCol(); } @@ -105,7 +105,7 @@ public function needsReset() { public function resetDayCount() { $this->state->set('statistics.day_timestamp', REQUEST_TIME); return (bool) $this->connection->update('node_counter') - ->fields(array('daycount' => 0)) + ->fields(['daycount' => 0]) ->execute(); } diff --git a/core/modules/statistics/src/StatisticsStorageInterface.php b/core/modules/statistics/src/StatisticsStorageInterface.php index ab65dae..feddc66 100644 --- a/core/modules/statistics/src/StatisticsStorageInterface.php +++ b/core/modules/statistics/src/StatisticsStorageInterface.php @@ -8,7 +8,8 @@ namespace Drupal\statistics; /** - * Provides an interface defining Statistics Storage + * Provides an interface defining Statistics Storage. + * * Stores the views per day, total views and timestamp of last view * for all nodes on the site. */ @@ -18,7 +19,7 @@ * Count a node view. * * @param int $nid - * The id of the node to count. + * The ID of the node to count. * * @return bool * TRUE if the node view has been counted. @@ -29,7 +30,7 @@ public function recordHit($nid); * Returns the number of times a node has been viewed. * * @param int $nid - * The id of the node to fetch the views for. + * The ID of the node to fetch the views for. * * @return array * An associative array containing: @@ -51,10 +52,10 @@ public function fetchViews($nid); * - 'timestamp' The unix timestamp of the last view. * * @param int $limit - * The number of node ids to return. + * The number of node IDs to return. * * @return array - * An ordered array of node ids. + * An ordered array of node IDs. */ public function fetchAll($order = 'totalcount', $limit = 5); @@ -62,7 +63,7 @@ public function fetchAll($order = 'totalcount', $limit = 5); * Delete counts for a specific node. * * @param int $nid - * The id of the node which views to delete. + * The ID of the node which views to delete. * * @return bool * TRUE if the node views have been deleted. diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 76a4f9e..0ab5f6e 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -19,13 +19,13 @@ function statistics_help($route_name, RouteMatchInterface $route_match) { case 'help.page.statistics': $output = ''; $output .= '
' . t('The Statistics module shows you how often content is viewed. This is useful in determining which pages of your site are most popular. For more information, see the online documentation for the Statistics module.', array('!statistics_do' => 'https://www.drupal.org/documentation/modules/statistics/')) . '
'; + $output .= '' . t('The Statistics module shows you how often content is viewed. This is useful in determining which pages of your site are most popular. For more information, see the online documentation for the Statistics module.', ['!statistics_do' => 'https://www.drupal.org/documentation/modules/statistics/']) . '
'; $output .= '