Add navigation menu omp 3.3 - #3 by trace (this one might actually be close to a solution, though I need to have a theme in addition to the generic plugin then, right? I am also unsure how addMenuArea() is correctly used in this case, with just one argument - how can I define the action for the area?)
Application Version - e.g., OJS 3.1.2:
OJS 3.3.x
Additional information, such as screenshots and error log messages if applicable:
I could override primaryNavMenu.tpl fully, but then I need to make sure to keep up with changes there. Unless there are other recommendations or ways that I’m missing, I might go that route.
I would also be fine with users having to add the menu item manually. For that, they could add an “external page” link. Since it looks easy to mess up the paths there, is there maybe a way to let a plugin add a new “Navigation Menu Type”, so that users just select the page that the plugin provides?
Hi @Vitaliy - thanks for the pointer. I did some searching for TemplateManager::display and load_menu in the source code, but I’m new to Smarty plugins and I’m not sure how to make such an override. Can you sketch the core steps in a few words? THANKS!
Thanks for that! The unregister is indeed needed, but then the regular menu is of course gone. So I suppose I could call the unregistered function from PKPTemplateManager within my function somehow and then append my page.
Alternatively, might it be more reasonable to directly interact with NavigationMenuDAO ?
Depending on a task. For a static menu item I’d probable modify the front-end part. If going this path, the menu item should be added only once, e.g., during plugin installation. But I think in this case it’s less complicated to add the item manually through the dashboard
Yeah, for something that has only to be done once, it might be more reasonable to add documentation instead of code.
Anyway, I can access the rendered menu HTML, so your suggestion does work:
public function doSomethingWithMenu($params, $smarty)
{
$menu = $smarty->smartyLoadNavigationMenuArea($params, $smarty);
// modify HTML of menu?
return $menu;
}
But that’s a bit hacky, of course. Maybe I am missing an idea here? Could there be a way to manipulate before the menu is handed over to the fetch(..) call and is rendered?
The only problem I have, but will ignore for now, is that this way, I’m both changing the main navigation menu and the admin menu at the top right:
Anyway, I am not 100% sure that my target users will be able to use the child theme, but until I have a definitive “no” on that I’ll go with this approach. Yet another hook that I might propose to PKP?
@Vitaliy Thank you for your patience and help! I wouldn’t have had any entry point to this problem without you.
$navigationMenuId = $smarty->getTemplateVars('id')
if ($navigationMenuId === 'navigationPrimary') {
....
}
Yes, there are basically 2 ways here, modify the returned by Smarty fetch() output or completely override the method without calling a smartyLoadNavigationMenuArea().