Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing multiple INavigationManager #12365

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IAdminMenuPermissionService, AdminMenuPermissionService>();

services.AddScoped<IAdminMenuService, AdminMenuService>();
services.AddScoped<AdminMenuNavigationProvidersCoordinator, AdminMenuNavigationProvidersCoordinator>();
Skrypt marked this conversation as resolved.
Show resolved Hide resolved
services.AddScoped<AdminMenuNavigationProvidersCoordinator>();

services.AddRecipeExecutionStep<AdminMenuStep>();

Expand Down
35 changes: 19 additions & 16 deletions src/OrchardCore.Modules/OrchardCore.Navigation/NavigationShapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,37 @@ public void Discover(ShapeTableBuilder builder)

var viewContextAccessor = context.ServiceProvider.GetRequiredService<ViewContextAccessor>();
var viewContext = viewContextAccessor.ViewContext;

var navigationManager = context.ServiceProvider.GetRequiredService<INavigationManager>();
var navigationManagers = context.ServiceProvider.GetServices<INavigationManager>();
Skrypt marked this conversation as resolved.
Show resolved Hide resolved
var shapeFactory = context.ServiceProvider.GetRequiredService<IShapeFactory>();
var httpContextAccessor = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>();
var menuItems = await navigationManager.BuildMenuAsync(menuName, viewContext);
var httpContext = httpContextAccessor.HttpContext;

if (httpContext != null)
foreach (var navigationManager in navigationManagers)
{
// adding query string parameters
var route = menu.GetProperty<RouteData>("RouteData");
var routeData = new RouteValueDictionary(route.Values);
var query = httpContext.Request.Query;
var menuItems = await navigationManager.BuildMenuAsync(menuName, viewContext);
var httpContext = httpContextAccessor.HttpContext;

if (query != null)
if (httpContext != null)
{
foreach (var pair in query)
// adding query string parameters
Skrypt marked this conversation as resolved.
Show resolved Hide resolved
var route = menu.GetProperty<RouteData>("RouteData");
var routeData = new RouteValueDictionary(route.Values);
var query = httpContext.Request.Query;

if (query != null)
{
if (pair.Key != null && !routeData.ContainsKey(pair.Key))
foreach (var pair in query)
{
routeData[pair.Key] = pair.Value;
if (pair.Key != null && !routeData.ContainsKey(pair.Key))
{
routeData[pair.Key] = pair.Value;
}
}
}
}
}

// TODO: Flag Selected menu item
await NavigationHelper.PopulateMenuAsync(shapeFactory, menu, menu, menuItems, viewContext);
// TODO: Flag Selected menu item
await NavigationHelper.PopulateMenuAsync(shapeFactory, menu, menu, menuItems, viewContext);
}
});

builder.Describe("NavigationItem")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static class ServiceCollectionExtensions
/// <returns></returns>
public static IServiceCollection AddNavigation(this IServiceCollection services)
{
services.TryAddScoped<INavigationManager, NavigationManager>();
Skrypt marked this conversation as resolved.
Show resolved Hide resolved

services.TryAddEnumerable(ServiceDescriptor.Scoped<INavigationManager, NavigationManager>());
Skrypt marked this conversation as resolved.
Show resolved Hide resolved
return services;
}
}
Expand Down