Commit d904faac authored by alexpott's avatar alexpott

Issue #2543554 by Wim Leers, tim.plunkett: Clean up Help & Statistics blocks

parent b8ac53f1
......@@ -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,
];
}
}
/**
......
......@@ -32,6 +32,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
'route.menu_active_trails:main',
'route.menu_active_trails:tools',
'timezone',
'url',
'user'
];
......
......@@ -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 />';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment