From d904faacf177aff1dac96b472f8711bd4c459d23 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 6 Aug 2015 17:20:58 +0100 Subject: [PATCH] Issue #2543554 by Wim Leers, tim.plunkett: Clean up Help & Statistics blocks --- .../help/src/Plugin/Block/HelpBlock.php | 32 +++------- .../node/src/Tests/NodeTranslationUITest.php | 1 + .../Plugin/Block/StatisticsPopularBlock.php | 62 +++++-------------- 3 files changed, 26 insertions(+), 69 deletions(-) diff --git a/core/modules/help/src/Plugin/Block/HelpBlock.php b/core/modules/help/src/Plugin/Block/HelpBlock.php index 7b86f9fc400a..abe3c254eadc 100644 --- a/core/modules/help/src/Plugin/Block/HelpBlock.php +++ b/core/modules/help/src/Plugin/Block/HelpBlock.php @@ -26,13 +26,6 @@ */ class HelpBlock extends BlockBase implements ContainerFactoryPluginInterface { - /** - * Stores the help text associated with the active menu item. - * - * @var string - */ - protected $help; - /** * The module handler. * @@ -92,19 +85,6 @@ public static function create(ContainerInterface $container, array $configuratio ); } - /** - * {@inheritdoc} - */ - protected function blockAccess(AccountInterface $account) { - $this->help = $this->getActiveHelp($this->request); - if ($this->help) { - return AccessResult::allowed(); - } - else { - return AccessResult::forbidden(); - } - } - /** * Returns the help associated with the active menu item. * @@ -125,9 +105,15 @@ protected function getActiveHelp(Request $request) { * {@inheritdoc} */ public function build() { - return array( - '#children' => $this->help, - ); + $help = $this->getActiveHelp($this->request); + if (!$help) { + return []; + } + else { + return [ + '#children' => $help, + ]; + } } /** diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index 5ddd64dc87e6..fe3a4bc1ce8a 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -32,6 +32,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { 'route.menu_active_trails:main', 'route.menu_active_trails:tools', 'timezone', + 'url', 'user' ]; diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php index 6dd6f7fccda9..621f6cf8ad88 100644 --- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php @@ -22,27 +22,6 @@ */ class StatisticsPopularBlock extends BlockBase { - /** - * Number of day's top views to display. - * - * @var int - */ - protected $day_list; - - /** - * Number of all time views to display. - * - * @var int - */ - protected $all_time_list; - - /** - * Number of most recent views to display. - * - * @var int - */ - protected $last_list; - /** * {@inheritdoc} */ @@ -58,23 +37,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'); } /** @@ -123,18 +86,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'] = '<br />'; + 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->all_time_list) { - $content['top_all'] = $this->all_time_list; - $content['top_all']['#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->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'] = '<br />'; } -- GitLab