private async Task BuildMenuLevels(NavigationItemBuilder urlTreeRoot, List <Level> levels) { foreach (var level in levels) { ContentItemMetadata cim = null; // Not all segments will have a content item associated with them. if (level.ContentItem != null) { cim = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(level.ContentItem); } // TODO fix for list, which by default uses display. Hmm is this fixed? if (cim != null) { cim.AdminRouteValues["Action"] = "Edit"; } await urlTreeRoot.AddAsync(level.DisplayText, level.DisplayText, async menuLevel => { if (level.ContentItem != null) { menuLevel.Action(cim.AdminRouteValues["Action"] as string, cim.AdminRouteValues["Controller"] as string, cim.AdminRouteValues); menuLevel.Resource(level.ContentItem); var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(level.ContentItem.ContentType); menuLevel.Permission(ContentTypePermissions.CreateDynamicPermission( ContentTypePermissions.PermissionTemplates[global::OrchardCore.Contents.Permissions.EditContent.Name], contentTypeDefinition)); } await BuildMenuLevels(menuLevel, level.SubLevels); }); } }
private async Task BuildMenuLevels(NavigationItemBuilder urlTreeRoot, List <TermMenuEntry> termMenuEntries, int level, RouteValueDictionary taxonomyRouteValues, TermMenuEntry parent = null) { foreach (var termMenuEntry in termMenuEntries.Where(x => x.Level == level)) { if (parent != null && termMenuEntry.Parent != parent) { continue; } //ContentItemMetadata cim = null; // Not all segments will have a content item associated with them. //if (termMenuEntry.ContentItem != null) //{ // cim = await _contentManager.PopulateAspectAsync<ContentItemMetadata>(termMenuEntry.ContentItem); //} //// TODO fix for list, which by default uses display. //if (cim != null) //{ // cim.AdminRouteValues["Action"] = "Edit"; //} var localizedDisplayText = new LocalizedString(termMenuEntry.Term.DisplayText, termMenuEntry.Term.DisplayText); await urlTreeRoot.AddAsync(localizedDisplayText, async menuLevel => { if (termMenuEntry.Term != null) { // TODO Clone taxonomyroutevalues and add this in. var termRouteValues = new RouteValueDictionary { { "Area", "OrchardCore.Contents" }, { "Controller", "Admin" }, { "Action", "Display" }, { "ContentItemId", taxonomyRouteValues["ContentItemId"] }, { "TaxonomyPart.TermContentItemId", termMenuEntry.Term.ContentItemId } }; menuLevel.Action(termRouteValues["Action"] as string, termRouteValues["Controller"] as string, termRouteValues); //menuLevel.Action(cim.AdminRouteValues["Action"] as string, cim.AdminRouteValues["Controller"] as string, cim.AdminRouteValues); //menuLevel.Resource(termMenuEntry.ContentItem); //var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(termMenuEntry.ContentItem.ContentType); //menuLevel.Permission(ContentTypePermissions.CreateDynamicPermission( // ContentTypePermissions.PermissionTemplates[global::OrchardCore.Contents.Permissions.EditContent.Name], contentTypeDefinition)); } //menuLevel.Caption(T["test"]); await BuildMenuLevels(menuLevel, termMenuEntries, level + 1, taxonomyRouteValues, termMenuEntry); }); } }