Skip to content

Commit

Permalink
pkp/pkp-lib#5199 Set the current page on the top menu - OPS 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
israelcefrin committed Jan 26, 2024
1 parent 2603d5f commit 13c282b
Show file tree
Hide file tree
Showing 2 changed files with 581 additions and 513 deletions.
55 changes: 52 additions & 3 deletions plugins/themes/default/DefaultThemePlugin.php
Original file line number Diff line number Diff line change
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-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class DefaultThemePlugin
Expand All @@ -17,9 +17,14 @@
use APP\core\Application;
use APP\file\PublicFileManager;
use PKP\config\Config;
use PKP\plugins\ThemePlugin;
use PKP\session\SessionManager;

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

class DefaultThemePlugin extends ThemePlugin
{
/**
Expand Down Expand Up @@ -210,6 +215,9 @@ public function init()

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


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

/**
Expand Down Expand Up @@ -253,6 +261,47 @@ 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();

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

return $emptyMarker;
}

}

if (!PKP_STRICT_MODE) {
Expand Down
Loading

0 comments on commit 13c282b

Please sign in to comment.