Last Updated: 2019-04-25
When adding new functionality to the manager you'll want to add items for your new page in the menu. The menu is a
static singleton object that can be changed or updated from anywhere, at any time. However, since the menu is the same for all users, changing it in runtime for the state of single user will not work.
If you are building a custom module, our recommendation is that you add your menu items in the
Init() method of your module. This will ensure that it will only be execute once in the application lifecycle.
If you are just adding menu items in your application we recommend that you do it in your
Piranha.App.Init() has been called.
Creating Menu Items
MenuItem class has the following properties that you should set when adding a new item to the menu.
As the menu is ordered into sections, at least the topmost level of items should have an Internal Id so that it's easy to access them when adding child items.
This is the display name that will printed out in the menu when it is folded out.
The controller that generated link should point to. As the topmost level of items are only used as sections, this property is not needed for these items.
The action that generated link should point to. As the topmost level of items are only used as sections, this property is not needed for these items.
The css class that will be added to the icon for the menu item. The manager interface uses the font icons from Font Awesome, so any of the icons there will work.
If you want to restrict the menu item depending on the claims of the currently logged in user. Please note that each item can only have one policy, a policy can however be a set of several claims.
Adding Menu Items
Please note that empty menu sections will not be rendered. The same also applies for menu sections only containing items that the current user don't have access to.
Adding a Menu Section
The following code will add a new section below the Settings section.
Menu.Items.Insert(2, new Menu.MenuItem
InternalId = "MyModule",
Name = "My Module",
Css = "fas fa-fish"
Adding a Menu Item
The following code will add a menu item under our new group.
InternalId = "FirstFunction",
Name = "First Function",
Controller = "MyModule",
Action = "FirstAction",
Css = "fas fa-brain",
Policy = "MyFirstFunction"