Admin menu

In this article, we will overview how to create an admin menu tab in the admin area.

 

Firstly create a class that implements IAdminMenuProvider that has one significant method. ManageSiteMap method receives root node.  In our simple plugin we want to create a tab in the following hierarchy - Extensions -> My plugin -> Configure.


Firstly we must check that the Extensions node exists, if not then create it. Then we create our plugin's main tab called MyPlugin then add to it a sub tab called Configuration.  SiteMapNode allows us to set ControllerName and ActionName, so we call make tab clickable and redirect to a specific URL after click. The most common use case is to create a tab that redirects to the configuration page.



var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "extensions");

                if (pluginNode == null)
                {
                    rootNode.ChildNodes.Add(new SiteMapNode() {
                        SystemName = "extensions",
                        ResourceName = "GrandNode.Sitemap.Extensions",
                        Visible = true,
                        IconClass = "icon-paper-clip"
                    });
                    pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "extensions");
                }

                SiteMapNode Menu = new SiteMapNode();
                Menu.ResourceName = "Plugins.Misc.MyPlugin";
                Menu.Visible = true;
                Menu.SystemName = "MyPlugin";
                Menu.ChildNodes.Add(new SiteMapNode() {
                    ResourceName = "Plugins.Misc.MyPlugin.Fields.Configuration",
                    Visible = true,
                    SystemName = "MyPlugin.Settings",
                    IconClass = "",
                    ControllerName = "MyPlugin",
                    ActionName = "Configure",
                });

                if (pluginNode != null)
                    pluginNode.ChildNodes.Add(Menu);
                else
                    rootNode.ChildNodes.Add(Menu); 
	


The last step is register our implementation in ioc container :

services.AddScoped<IAdminMenuProvider,MyPluginAdminMenuProvider>();


Result:


 

Morty Proxy This is a proxified and sanitized view of the page, visit original site.