.../src/Plugin/Block/StatisticsPopularBlock.php | 44 +++++++++-------------
1 file changed, 17 insertions(+), 27 deletions(-)
diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
index daa0e09..85b9de3 100644
--- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
+++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
@@ -9,7 +9,6 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
-use Drupal\Core\Block\NonLazyBuildableBlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
@@ -21,7 +20,7 @@
* admin_label = @Translation("Popular content")
* )
*/
-class StatisticsPopularBlock extends BlockBase implements NonLazyBuildableBlockPluginInterface {
+class StatisticsPopularBlock extends BlockBase {
/**
* Number of day's top views to display.
@@ -59,23 +58,7 @@ public function defaultConfiguration() {
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
- $access = AccessResult::allowedIfHasPermission($account, 'access content');
- if ($account->hasPermission('access content')) {
- $daytop = $this->configuration['top_day_num'];
- if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->day_list = node_title_list($result, $this->t("Today's:")))) {
- return AccessResult::forbidden()->inheritCacheability($access);
- }
- $alltimetop = $this->configuration['top_all_num'];
- if (!$alltimetop || !($result = statistics_title_list('totalcount', $alltimetop)) || !($this->all_time_list = node_title_list($result, $this->t('All time:')))) {
- return AccessResult::forbidden()->inheritCacheability($access);
- }
- $lasttop = $this->configuration['top_last_num'];
- if (!$lasttop || !($result = statistics_title_list('timestamp', $lasttop)) || !($this->last_list = node_title_list($result, $this->t('Last viewed:')))) {
- return AccessResult::forbidden()->inheritCacheability($access);
- }
- return $access;
- }
- return AccessResult::forbidden()->inheritCacheability($access);
+ return AccessResult::allowedIfHasPermission($account, 'access content');
}
/**
@@ -124,18 +107,25 @@ public function blockSubmit($form, FormStateInterface $form_state) {
public function build() {
$content = array();
- if ($this->day_list) {
- $content['top_day'] = $this->day_list;
- $content['top_day']['#suffix'] = '
';
+ 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'] = '
';
+ }
}
- if ($this->all_time_list) {
- $content['top_all'] = $this->all_time_list;
- $content['top_all']['#suffix'] = '
';
+ 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'] = '
';
+ }
}
- if ($this->last_list) {
- $content['top_last'] = $this->last_list;
+ 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'] = '
';
}