Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong navigation menu URLs when using site-wide menu #10861

Open
NateWr opened this issue Jan 30, 2025 · 0 comments
Open

Wrong navigation menu URLs when using site-wide menu #10861

NateWr opened this issue Jan 30, 2025 · 0 comments

Comments

@NateWr
Copy link
Contributor

NateWr commented Jan 30, 2025

Describe the bug
When loading a site-level navigation menu at the context level, the URLs for navigation menu items are not correct. The URLs are generated assuming they point to the same context as the request.

To Reproduce
Steps to reproduce the behavior:

  1. Add the suggested code below to a theme and use it to assign the result to a template variable.
  2. Add a navigation menu at the site level (Administration > Site Settings > Navigation) with at least one custom page.
  3. View the resulting code on a journal and see that the custom page URL doesn't point to the site-level custom page.

What application are you using?
stable-3_3_0

Additional information
The following code can be used in a theme to load a navigation menu defined at the site level. This is used, for example, to load a publisher or hosting service menu on every journal's site.

protected function getMenu(string $name, int $contextId =  CONTEXT_ID_NONE, string $path = ''): string
{
    /** @var NavigationMenuDAO $navigationMenuDao */
    $navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO');
    $navigationMenus = $navigationMenuDao->getByArea($contextId, $name)->toArray();

    if (!isset($navigationMenus[0])) {
        return '';
    }

    $navigationMenu = $navigationMenus[0];
    Services::get('navigationMenu')->getMenuTree($navigationMenu);

    $templateMgr = TemplateManager::getManager(Application::get()->getRequest());
    $templateMgr->assign([
        'navigationMenu' => $navigationMenu,
        'id' => '',
        'ulClass' => '',
        'liClass' => '',
    ]);

    if (!$path) {
        $path = 'frontend/components/navigationMenu.tpl';
    }

    return $templateMgr->fetch($path);
}```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant