Backend Menu

When you develop a custom Platformus CMS extension you might need to add items to the backend (admin panel) menu. All the backend menu groups and items are defined in the extensions. Each extension can provide one or more implementations of the IMetadata interface which allows to specify, among other things, the menu items grouped by the menu groups. It is preferable to use the MetadataBase class to be able to override only the methods you want:

public class MyMetadata : MetadataBase
  public override IEnumerable<MenuGroup> GetMenuGroups(HttpContext httpContext)
    IStringLocalizer<Metadata> localizer = httpContext.GetStringLocalizer<Metadata>();

    return new MenuGroup[]
      new MenuGroup(
        localizer["My Group"],
        new MenuItem[]
          new MenuItem("icon--icon1", "/backend/something-1", localizer["Something 1"], 1000, "ManageSomething1"),
          new MenuItem("icon--icon2", "/backend/something-2", localizer["Something 2"], 2000, "ManageSomething2"),
          new MenuItem("icon--icon3", "/backend/something-3", localizer["Something 3"], 3000, "ManageSomething3")

This file can be placed anywhere in the project, it will be resolved automatically by the default implementation of the IMenuGroupsProvider interface.

If the provided menu group’s name matches name of the existing one, the menu items of both will be merged into the single group according to the menu item positions.

Let’s look at the MenuItem class’s properties.

CssClass allows to specify the CSS class that will be added to the menu item HTML tag. Intended to provide a custom icon but can also be used to apply another styling.

Url is the URL where user is navigated when clicks the menu item.

Name is displayed in the menu.

Position is used to sort the menu items (and menu groups). Items with a lower position are placed higher.

PermissionCodes contains an array of the codes of the permissions which are required for user to have in order to see the menu item.