Adding Items to the Dashboard Menu and Sub-menu Items to the page tabs

Topics: Writing modules
Apr 25, 2011 at 8:27 AM

Morning :D

Can anyone provide any information or point me in the right direction on how I would create my own section in the Dashboard menu for a module I am creating?
I would also like to make certain functionality available from the tabs on the right panel (or as sub-menu items in the main menu) for the creation of new Content Items,
much like you currently see under "New" So for example I would have:

 

Zoo
    Animal
    Building
    Restaurant  
    Souvenir Shop With Extortionate Prices  

 

TIA

Nick

 

 

 

Apr 25, 2011 at 9:41 AM

Morning Nick,

Well any new content types you create will automatically appear under "New" (if you're creating them in code you have to declare them as Creatable and they should show)

That "New" menu is built from Orchard.Core.Contents.AdminMenu.cs (which is an implementation of INavigationProvider).

So you can implement INavigationProvider yourself to add anything you want to; even adding new tabs to those existing menus.

The Menu API is a bit confusing but the important thing to note is that when you create a menu item you can use the .LocalNav() method to declare an item as a Tab instead of going on the LHS.

That should help you get started anyways :)

Apr 25, 2011 at 10:40 AM
Edited Apr 25, 2011 at 10:45 AM

Cheers Pete.

 

I was just rummaging around in the code and found out by looking at Modules\Orchard.Pages\Migrations.cs that you could declare types as creatable :D

Also for anyone who may come across this post in the future that may find it useful you can also create them as draftable, and attachable too. (see Orchard.Core\Contents\Extensions\MetaDataExtensions.cs )

 

I also noticed that a lot of the modules have The AdminMenu.cs file in the root. For example:

---------------------------------------------------------------------------------------------------------

namespace Orchard.Core.Dashboard {
    public class AdminMenu : INavigationProvider {
        public Localizer T { getset; }
        public string MenuName { get { return "admin"; } }

        public void GetNavigation(NavigationBuilder builder) {
            builder.AddImageSet("dashboard")
                .Add(T("Dashboard"), "-5",
                    menu => menu.Add(T("Orchard"), "-5",
                        item => item
                            .Action("Index""Admin"new { area = "Dashboard" })
                            .Permission(StandardPermissions.AccessAdminPanel)));
        }
    }
}

--------------------------------------------------------------------------------------------------------- 

namespace Orchard.ContentTypes {
    public class AdminMenu : INavigationProvider {

        public Localizer T { getset; }
        public string MenuName { get { return "admin"; } }

        public void GetNavigation(NavigationBuilder builder) {

            builder.Add(T("Content"),
                        menu => menu.Add(T("Content Types"), "3", item => item.Action("Index""Admin"new { area = "Orchard.ContentTypes" }).LocalNav()));
        }
    }
}

---------------------------------------------------------------------------------------------------------

 

So I guess I will have a tinker around with these to gain an understanding of how it all fits together ;)

 

Nick

Apr 25, 2011 at 12:19 PM
Edited Apr 25, 2011 at 12:19 PM

That's it exactly.

Just to note, when you call:

 builder.Add(T("Content") ...

What will actually happen is if the menu already exists, it won't create a new menu - instead it lets you edit that menu and add / change items in it.

BTW; Attachable() is for ContentParts, to declare that they can be used in the Admin UI for building new content types.