This project is read-only.


Admin menu subitems don't show if there is only one


The following shows only TopItem:
public class AdminMenu : INavigationProvider
    public Localizer T { get; set; }
    public string MenuName { get { return "admin"; } }

    public void GetNavigation(NavigationBuilder builder)
        builder.Add(T("TopItem"), "1.5", BuildMenu);

    private void BuildMenu(NavigationItemBuilder menu)
         menu.Action("LogOn", "Account", new { area = "Orchard.Users" });
        menu.Add(T("SubItem"), "1",
            item => item.Action("AccessDenied", "Account", new { area = "Orchard.Users" }));
(Orchard.Users used for demonstration only.)
This works, however with menu.LinkToFirstChild(false); I think this shouldn't be needed to be set explicitly.
This issue could be related:


BertrandLeRoy wrote Jul 12, 2012 at 7:23 PM

I'm pretty sure this is by design.

Piedone wrote Jul 12, 2012 at 7:38 PM

But what was the purpose of the designer with this? :-)

DavidCornish wrote Sep 24, 2012 at 6:01 PM

This bug is fairly trivial; in the admin theme, in menu.cshtml, around line 69 is a line:

if (secondLevelMenuItems.Where(menuItem => !menuItem.LocalNav).Count() > 1 || !firstLevelMenuItem.LinkToFirstChild) {

this should instead read >=1 so that if there is a single sub-menu item, it is still rendered.

DavidCornish wrote Sep 24, 2012 at 6:11 PM

Actually, just making that change, and it seems that a lot of the modules are set up so that they have a single sub-menu item, and assume LinkToFirstChild is true. So with this "fix" there become a lot of sub-menus! The blogs module seems a good example of how this can be used to good effect.

So my conclusion is that Bertrand's "by design" is that LinkToFirstChild is enabled by default, so a single child menu collapses down to one entry.

If there's a bug here, it's that despite LinkToFirstChild being set to true on the first level item, the action specified is still used. This is because in menu.cshtml the test for whether there is an action present on a menu item comes before the test for LinkToFirstChild.

DavidCornish wrote Sep 24, 2012 at 6:17 PM

sebastienros wrote Sep 29, 2012 at 2:03 AM

changeset 5e345d925819

sfmskywalker wrote Mar 28, 2014 at 1:28 AM

Fixed in changeset d893ebbcfd7eb1abf4c27a504d473a6bee56ec19