Admin menu / more levels add by ManageSiteMapAsync()

10 месяцев назад
Hello,
i added item to admin menu, via ManageSiteMapAsync(). Version 4.6

When i try to add/append childs to these new item, dropdown don ´t show. Here is still only one parent item.


public Task ManageSiteMapAsync(SiteMapNode rootNode)
        {
          
            var child1 = new SiteMapNode()   {....}
            var child2 = new SiteMapNode()   {....}
            var parent  = new SiteMapNode()   {....}
            
            parent.ChildNodes.Append(child1);
            parent.ChildNodes.Append(child2);

            rootNode.ChildNodes.Append(parent )

            return Task.CompletedTask;
        }


Thank you for help.
10 месяцев назад
When adding a sub menu heading dont use a ControllerName and ActionName for that option i.e as in the Organisation option below

                var lrs = await _localizationService.GetResourceAsync("Plugins.Group.Name.Menu");
                if (lrs != null)
                {
                    mainMenuItem = new SiteMapNode()
                    {
                        SystemName = "Nop.Plugin.Group.Name.Menu",
                        Title = lrs,
                        IconClass = "fa fa-users",
                        Visible = true
                    };
                }

                lrs = await _localizationService.GetResourceAsync("Plugins.Group.Name.Organisation");
                if (lrs != null)
                {
                    manageOrganisation = new SiteMapNode()
                    {
                        SystemName = "Nop.Plugin.Group.Name.Organisation",
                        Title = lrs,
                        Visible = true,
                        IconClass = "fa fa-industry",
                        RouteValues = new RouteValueDictionary() { { "area", "Admin" } },
                    };
                }

                lrs = await _localizationService.GetResourceAsync("Plugins.Group.Name.Company");
                if (lrs != null)
                {
                    manageCompanies = new SiteMapNode()
                    {
                        SystemName = "Nop.Plugin.Group.Name.Company",
                        Title = lrs,
                        ControllerName = "Company",
                        ActionName = "CompanyList",
                        Visible = true,
                        IconClass = "fa fa-building",
                        RouteValues = new RouteValueDictionary() { { "area", "Admin" } },
                    };
                }

               manageOrganisation.ChildNodes.Add(manageCompanies);
               mainMenuItem.ChildNodes.Add(manageOrganisation);
               rootNode.ChildNodes.Add(mainMenuItem);
10 месяцев назад
Thank you,

and can you send example, how can i restrict for example one of child with ACL?

Jakub
10 месяцев назад
One way is to only add the option to the menu if a customer has a specific Permssion
You can also create your own permissions

if (await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers))
{
                lrs = await _localizationService.GetResourceAsync("Plugins.Group.Name.Company");
                if (lrs != null)
                {
                    manageCompanies = new SiteMapNode()
                    {
                        SystemName = "Nop.Plugin.Group.Name.Company",
                        Title = lrs,
                        ControllerName = "Company",
                        ActionName = "CompanyList",
                        Visible = true,
                        IconClass = "fa fa-building",
                        RouteValues = new RouteValueDictionary() { { "area", "Admin" } },
                    };
                }

               manageOrganisation.ChildNodes.Add(manageCompanies);
}