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 26, 2024
1 parent 9a29c1d commit 0488910
Show file tree
Hide file tree
Showing 2 changed files with 582 additions and 507 deletions.
57 changes: 53 additions & 4 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 @@ -211,6 +216,8 @@ 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 @@ -254,8 +261,50 @@ 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) {
class_alias('\APP\plugins\themes\default\DefaultThemePlugin', '\DefaultThemePlugin');
}
}
Loading

0 comments on commit 0488910

Please sign in to comment.