Skip to content

Commit

Permalink
Merge pull request pkp#10723 from jonasraoni/bugfix-main-10720-fix-na…
Browse files Browse the repository at this point in the history
…vigation-menu

Bugfix main 10720 fix navigation menu
  • Loading branch information
bozana authored Dec 18, 2024
2 parents 2ece20b + 852f0e2 commit 436fd69
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions pages/navigationMenu/NavigationMenuItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@

class NavigationMenuItemHandler extends Handler
{
/** @var NavigationMenuItem The nmi to view */
public $nmi;

public function __construct($nmi)
public function __construct(public ?NavigationMenuItem $nmi = null)
{
$this->nmi = $nmi;
}

//
Expand All @@ -57,7 +53,6 @@ public function authorize($request, &$args, $roleAssignments)
*/
public function preview($args, $request)
{
$path = array_shift($args);
$context = $request->getContext();
// Ensure that if we're previewing, the current user is a manager or admin.
$roles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES);
Expand All @@ -77,8 +72,6 @@ public function preview($args, $request)

app()->get('navigationMenu')->transformNavMenuItemTitle($templateMgr, $navigationMenuItem);

$templateMgr->assign('title', $navigationMenuItem->getLocalizedTitle());

$vars = [];
if ($context) {
$vars = [
Expand All @@ -90,7 +83,10 @@ public function preview($args, $request)
];
}

$templateMgr->assign('content', strtr($navigationMenuItem->getLocalizedContent(), $vars));
$templateMgr->assign([
'title' => $navigationMenuItem->getLocalizedTitle(),
'content' => strtr($navigationMenuItem->getLocalizedContent(), $vars)
]);

$templateMgr->display('frontend/pages/navigationMenuItemViewContent.tpl');
}
Expand All @@ -103,40 +99,31 @@ public function preview($args, $request)
*/
public function view($args, $request)
{
$path = array_shift($args);
$context = $request->getContext();
$contextId = \PKP\core\PKPApplication::SITE_CONTEXT_ID;
if ($context) {
$contextId = $context->getId();
if (!isset($this->nmi)) {
return false;
}

// Assign the template vars needed and display
$templateMgr = TemplateManager::getManager($request);
$this->setupTemplate($request);

$navigationMenuItemDao = DAORegistry::getDAO('NavigationMenuItemDAO'); /** @var NavigationMenuItemDAO $navigationMenuItemDao */

$navigationMenuItem = $navigationMenuItemDao->getByPath($contextId, $path);

if (isset($this->nmi)) {
$templateMgr->assign('title', $this->nmi->getLocalizedTitle());

$vars = [];
if ($context) {
$vars = [
'{$contactName}' => $context->getData('contactName'),
'{$contactEmail}' => $context->getData('contactEmail'),
'{$supportName}' => $context->getData('supportName'),
'{$supportPhone}' => $context->getData('supportPhone'),
'{$supportEmail}' => $context->getData('supportEmail'),
];
}
$templateMgr->assign('content', strtr($this->nmi->getLocalizedContent(), $vars));

$templateMgr->display('frontend/pages/navigationMenuItemViewContent.tpl');
} else {
return false;
$vars = [];
$context = $request->getContext();
if ($context) {
$vars = [
'{$contactName}' => $context->getData('contactName'),
'{$contactEmail}' => $context->getData('contactEmail'),
'{$supportName}' => $context->getData('supportName'),
'{$supportPhone}' => $context->getData('supportPhone'),
'{$supportEmail}' => $context->getData('supportEmail'),
];
}
$templateMgr->assign([
'title' => $this->nmi->getLocalizedTitle(),
'content' => strtr($this->nmi->getLocalizedContent(), $vars)
]);

$templateMgr->display('frontend/pages/navigationMenuItemViewContent.tpl');
}

/**
Expand Down

0 comments on commit 436fd69

Please sign in to comment.