Skip to content

Commit

Permalink
pkp/pkp-lib#5199 Set the current page on the top menu - OMP 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
israelcefrin committed Jan 25, 2024
1 parent 9a29c1d commit d2738ce
Show file tree
Hide file tree
Showing 2 changed files with 609 additions and 523 deletions.
100 changes: 80 additions & 20 deletions plugins/themes/default/DefaultThemePlugin.php
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/themes/default/DefaultThemePlugin.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2003-2022 John Willinsky
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class DefaultThemePlugin
Expand All @@ -17,10 +17,16 @@
use APP\core\Application;
use APP\file\PublicFileManager;
use PKP\config\Config;
use PKP\plugins\ThemePlugin;
use PKP\session\SessionManager;

class DefaultThemePlugin extends ThemePlugin
use APP\facades\Repo;
use APP\issue\Collector;
use APP\services\NavigationMenuService;
use PKP\plugins\ThemePlugin;
use PKP\plugins\Hook;


class DefaultThemePlugin extends \PKP\plugins\ThemePlugin
{
/**
* @copydoc ThemePlugin::isActive()
Expand Down Expand Up @@ -77,35 +83,34 @@ public function init()
],
'default' => 'notoSans',
]);
$this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.label'),
'description' => __('plugins.themes.default.option.useHomepageImageAsHeader.description'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option')
],
],
'default' => false,
]);

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

$this->addOption('showCatalogSeriesListing', 'FieldOptions', [
'label' => __('plugins.themes.default.option.showCatalogSeriesListing.label'),
$this->addOption('showDescriptionInJournalIndex', 'FieldOptions', [
'label' => __('manager.setup.contextSummary'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.showCatalogSeriesListing.option')
'label' => __('plugins.themes.default.option.showDescriptionInJournalIndex.option'),
],
],
'default' => false,
]);
$this->addOption('useHomepageImageAsHeader', 'FieldOptions', [
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.label'),
'description' => __('plugins.themes.default.option.useHomepageImageAsHeader.description'),
'options' => [
[
'value' => true,
'label' => __('plugins.themes.default.option.useHomepageImageAsHeader.option')
],
],
'default' => false,
]);

$this->addOption('displayStats', 'FieldOptions', [
'type' => 'radio',
'label' => __('plugins.themes.default.option.displayStats.label'),
Expand All @@ -126,6 +131,7 @@ public function init()
'default' => 'none',
]);


// Load primary stylesheet
$this->addStyle('stylesheet', 'styles/index.less');

Expand Down Expand Up @@ -211,10 +217,13 @@ public function init()

// Add navigation menu areas for this theme
$this->addMenuArea(['primary', 'user']);


Hook::add('TemplateManager::display', array($this, 'checkCurrentPage'));
}

/**
* Get the name of the settings file to be installed on new press
* Get the name of the settings file to be installed on new journal
* creation.
*
* @return string
Expand Down Expand Up @@ -254,6 +263,57 @@ public function getDescription()
{
return __('plugins.themes.default.description');
}

/**
* @param $hookname string
* @param $args array
*/
public function checkCurrentPage($hookname, $args) {
$templateMgr = $args[0];
// TODO check the issue with multiple calls of the hook on settings/website
if (!isset($templateMgr->registered_plugins["function"]["default_item_active"])) {
$templateMgr->registerPlugin('function', 'default_item_active', array($this, 'isActiveItem'));
}

}

/**
* @param $params array
* @param $smarty Smarty_Internal_Template
* @return string
*/
public function isActiveItem($params, $smarty) {

$navigationMenuItem = $params['item'];
$emptyMarker = '';
$activeMarker = ' active';

// Get URL of the current page
$request = $this->getRequest();
$currentUrl = $request->getCompleteUrl();
$currentPage = $request->getRequestedPage();

// Do not add an active marker if it's a dropdown menu
if ($navigationMenuItem->getIsChildVisible()) return $emptyMarker;

// Retrieve URL and its components for a menu item
$itemUrl = $navigationMenuItem->getUrl();

// Check whether menu item points to the current page
/*$context = $request->getContext();
if ($context) {
$currentIssue = Repo::issue()->getCurrent($context->getId());
if ($navigationMenuItem->getType() === NavigationMenuService::NMI_TYPE_CURRENT) {
$issue = $smarty->getTemplateVars('issue');
if ($issue && ($issue->getId() === $currentIssue->getId()) && $currentPage == "issue") return $activeMarker;
}
}*/

if ($currentUrl === $itemUrl) return $activeMarker;

return $emptyMarker;
}

}

if (!PKP_STRICT_MODE) {
Expand Down

0 comments on commit d2738ce

Please sign in to comment.