Adding to existing AdminMenu item

Topics: Administration, Customizing Orchard
Apr 17, 2012 at 3:46 PM
Edited Apr 17, 2012 at 3:46 PM

We have a page that we'd like to add to the admin menu...we currently have that working with the code below.  What we'd like to do is add this as a child to an existing menu item, specifically the "Content" menu item.  I haven't been able to figure it out, as the best I could do was replace the content menu item with my new one, and that's not what I want.

Here's the code:

 

public void GetNavigation(NavigationBuilder builder)
        {
            builder.AddImageSet("modules")
              .Add(T("Page List"), "2",
                          menu => menu.Add(T("Page List"), "0",
                              item => item.Action("Pages", "Admin", new { area = "OurProject.SlugMenu" })
                                                                                .Permission(StandardPermissions.AccessAdminPanel)));
        }
Developer
Apr 17, 2012 at 4:02 PM

I believe that Bertrand's Vandelay Industries module contains a feature that does exactly that: modify an existing admin menu item by adding child menu items to it. The feature will display a sub menu of all the creatable content types.

Apr 17, 2012 at 4:05 PM

Thanks sfmskywalker, I'll look into it.  I couldn't find a good example, but not that I have one, I'll check it out...

Apr 17, 2012 at 4:07 PM

I assume you're talking about this one:

http://gallery.orchardproject.net/List/Modules/Orchard.Module.Vandelay.Industries

Otherwise, there are lots of Vandelay modules:

http://gallery.orchardproject.net/List/Search?packageType=Modules&searchTerm=vandelay

Apr 17, 2012 at 6:33 PM

I was able to get it to work with this code:

public void GetNavigation(NavigationBuilder builder)
        {

            builder
                .Add(T("Content"), "1.4", menu =>
                {
                    menu.LinkToFirstChild(false);
                    menu.Add(T("Page List"), "1", item =>
                                                  item.Action("Pages", "Admin", new {area = "OurProject.SlugMenu"})
                                                      .Permission(StandardPermissions.AccessAdminPanel));
                });
        }

The problem is that it repeats the icon for "Content" 3 times horizontally...not sure why that'd happen.  Also, what does the "LinkToFirstChild" do?

Apr 17, 2012 at 7:48 PM

Here's a pic of what it's doing below...I installed the Vandelay module and it doesn't do this, but when I copy his ContentAdminMenu.cs code into my project, it looks like this:

Developer
Apr 17, 2012 at 7:54 PM

Hey tjans. Yeah I meant the complete Vandelay Industries bundle: it contains all of the other Vandelay modules (which are deprecated by the way).

I can't say why the icon repeates horizontally. Sounds like a CSS issue. Did you find the code in the Vandelay module? Perhaps you should try to install it and enable the "Vandelay.ContentAdminMenu" feeature to see if it has the same problem.

The LinkToFirstChild method causes the menu item to point to the url of its first child menu item.

Apr 17, 2012 at 7:56 PM

I did install the vandelay module and it doesn't ahve the same issue...not sure why...it's definitely a CSS issue...when Iremove the class on that span, the icons go away...

Apr 18, 2012 at 12:55 PM
Edited Apr 18, 2012 at 12:58 PM

When I copy the code exactly from the Vandelay module, it has the "repeating" issue.  I must not have copied something from the Vandelay module or something.  I noticed that when I open it up in firebug and add characters to the "content" menu item, the background image continues to repeat..

Just for testing, I put in

background-repeat:no-repeat;

in the menu.content-admin.css and it stops the repeating, but it still puts the background image over the "content" menu item and the content menu item isn't indented. 

Apr 18, 2012 at 2:49 PM

Ok, more investigating. My naked eye couldn't see this, but when I ran the source with my adminmenu.cs commented out vs. the source with it included through Beyond Compare, I noticed this:

With Custom AdminMenu.cs:
<h3><span class="navicon-content">Content</span></h3>

Without Custom AdminMenu.cs:
<h3><a class="navicon-content" href="/Admin/Contents/List">Content</a></h3>

Apr 18, 2012 at 3:07 PM

So, when I set LinkToFirstChild to be true in the code I copied from Bertrand, it actually renders "content" as a link and therefore is styled appropriately.  Bertrand has his set to false, but it still works. Very confused...

Apr 18, 2012 at 4:09 PM

I'm goign to keep posting in case anyone is following along and runs into the same issues...

LinkToChild had to be set true so it rendered "Content" as a link. Still no idea why this is needed in mine but not the Vandelay module.


I have one remaining issue.  The following code below works (mostly):

public void GetNavigation(NavigationBuilder builder)
        {
            builder
                .AddImageSet("content")
                .Add(T("Content"), "1.4", menu =>
                {
                    menu.LinkToFirstChild(true);

                    menu.Add(T("Page List"), "0", item =>
                                item.Action("Pages", "Admin",
                                new RouteValueDictionary {
                                    {"area", "OurProject.SlugMenu"}
                                })
                                .Permission(StandardPermissions.AccessAdminPanel));

                    menu.Add(T("Dummy Entry"), "1", item =>
                        item.Action("Dummy", "Dummy",
                        new RouteValueDictionary {
                                {"area", "Dummy"}
                            })
                        .Permission(StandardPermissions.AccessAdminPanel));
                });
        }

But, if I remove that second "dummy entry" it renders the "Content" main menu item, but none of the children (e.g., Page List). Why does that dummy entry need to be there? I'll need to scour the error logs to see if there are any issues getting logged there.

Jan 11, 2014 at 11:29 AM
Any updates on the above?