Skip to content

Commit d2738ce

Browse files
committed
pkp/pkp-lib#5199 Set the current page on the top menu - OMP 3.4
1 parent 9a29c1d commit d2738ce

File tree

2 files changed

+609
-523
lines changed

2 files changed

+609
-523
lines changed

plugins/themes/default/DefaultThemePlugin.php

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/**
44
* @file plugins/themes/default/DefaultThemePlugin.php
55
*
6-
* Copyright (c) 2014-2022 Simon Fraser University
7-
* Copyright (c) 2003-2022 John Willinsky
6+
* Copyright (c) 2014-2021 Simon Fraser University
7+
* Copyright (c) 2003-2021 John Willinsky
88
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
99
*
1010
* @class DefaultThemePlugin
@@ -17,10 +17,16 @@
1717
use APP\core\Application;
1818
use APP\file\PublicFileManager;
1919
use PKP\config\Config;
20-
use PKP\plugins\ThemePlugin;
2120
use PKP\session\SessionManager;
2221

23-
class DefaultThemePlugin extends ThemePlugin
22+
use APP\facades\Repo;
23+
use APP\issue\Collector;
24+
use APP\services\NavigationMenuService;
25+
use PKP\plugins\ThemePlugin;
26+
use PKP\plugins\Hook;
27+
28+
29+
class DefaultThemePlugin extends \PKP\plugins\ThemePlugin
2430
{
2531
/**
2632
* @copydoc ThemePlugin::isActive()
@@ -77,35 +83,34 @@ public function init()
7783
],
7884
'default' => 'notoSans',
7985
]);
80-
$this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
81-
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.label'),
82-
'description' => __('plugins.themes.default.option.useHomepageImageAsHeader.description'),
83-
'options' => [
84-
[
85-
'value' => true,
86-
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option')
87-
],
88-
],
89-
'default' => false,
90-
]);
9186

9287
$this->addOption('baseColour', 'FieldColor', [
9388
'label' => __('plugins.themes.default.option.colour.label'),
9489
'description' => __('plugins.themes.default.option.colour.description'),
9590
'default' => '#1E6292',
9691
]);
9792

98-
$this->addOption('showCatalogSeriesListing', 'FieldOptions', [
99-
'label' => __('plugins.themes.default.option.showCatalogSeriesListing.label'),
93+
$this->addOption('showDescriptionInJournalIndex', 'FieldOptions', [
94+
'label' => __('manager.setup.contextSummary'),
10095
'options' => [
10196
[
10297
'value' => true,
103-
'label' => __('plugins.themes.default.option.showCatalogSeriesListing.option')
98+
'label' => __('plugins.themes.default.option.showDescriptionInJournalIndex.option'),
99+
],
100+
],
101+
'default' => false,
102+
]);
103+
$this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
104+
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.label'),
105+
'description' => __('plugins.themes.default.option.useHomepageImageAsHeader.description'),
106+
'options' => [
107+
[
108+
'value' => true,
109+
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option')
104110
],
105111
],
106112
'default' => false,
107113
]);
108-
109114
$this->addOption('displayStats', 'FieldOptions', [
110115
'type' => 'radio',
111116
'label' => __('plugins.themes.default.option.displayStats.label'),
@@ -126,6 +131,7 @@ public function init()
126131
'default' => 'none',
127132
]);
128133

134+
129135
// Load primary stylesheet
130136
$this->addStyle('stylesheet', 'styles/index.less');
131137

@@ -211,10 +217,13 @@ public function init()
211217

212218
// Add navigation menu areas for this theme
213219
$this->addMenuArea(['primary', 'user']);
220+
221+
222+
Hook::add('TemplateManager::display', array($this, 'checkCurrentPage'));
214223
}
215224

216225
/**
217-
* Get the name of the settings file to be installed on new press
226+
* Get the name of the settings file to be installed on new journal
218227
* creation.
219228
*
220229
* @return string
@@ -254,6 +263,57 @@ public function getDescription()
254263
{
255264
return __('plugins.themes.default.description');
256265
}
266+
267+
/**
268+
* @param $hookname string
269+
* @param $args array
270+
*/
271+
public function checkCurrentPage($hookname, $args) {
272+
$templateMgr = $args[0];
273+
// TODO check the issue with multiple calls of the hook on settings/website
274+
if (!isset($templateMgr->registered_plugins["function"]["default_item_active"])) {
275+
$templateMgr->registerPlugin('function', 'default_item_active', array($this, 'isActiveItem'));
276+
}
277+
278+
}
279+
280+
/**
281+
* @param $params array
282+
* @param $smarty Smarty_Internal_Template
283+
* @return string
284+
*/
285+
public function isActiveItem($params, $smarty) {
286+
287+
$navigationMenuItem = $params['item'];
288+
$emptyMarker = '';
289+
$activeMarker = ' active';
290+
291+
// Get URL of the current page
292+
$request = $this->getRequest();
293+
$currentUrl = $request->getCompleteUrl();
294+
$currentPage = $request->getRequestedPage();
295+
296+
// Do not add an active marker if it's a dropdown menu
297+
if ($navigationMenuItem->getIsChildVisible()) return $emptyMarker;
298+
299+
// Retrieve URL and its components for a menu item
300+
$itemUrl = $navigationMenuItem->getUrl();
301+
302+
// Check whether menu item points to the current page
303+
/*$context = $request->getContext();
304+
if ($context) {
305+
$currentIssue = Repo::issue()->getCurrent($context->getId());
306+
if ($navigationMenuItem->getType() === NavigationMenuService::NMI_TYPE_CURRENT) {
307+
$issue = $smarty->getTemplateVars('issue');
308+
if ($issue && ($issue->getId() === $currentIssue->getId()) && $currentPage == "issue") return $activeMarker;
309+
}
310+
}*/
311+
312+
if ($currentUrl === $itemUrl) return $activeMarker;
313+
314+
return $emptyMarker;
315+
}
316+
257317
}
258318

259319
if (!PKP_STRICT_MODE) {

0 commit comments

Comments
 (0)