Skip to content

Commit

Permalink
Show ThemeToggler on supported themes only (#17243)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Dec 18, 2024
1 parent a3b6f9e commit cebac22
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Themes/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Admin.Models;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Theming;
Expand Down Expand Up @@ -31,7 +30,6 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IThemeService, ThemeService>();
services.AddScoped<ThemeTogglerService>();
services.AddDeployment<ThemesDeploymentSource, ThemesDeploymentStep, ThemesDeploymentStepDriver>();
services.AddDisplayDriver<Navbar, ToggleThemeNavbarDisplayDriver>();
services.AddDisplayDriver<ThemeEntry, ThemeEntryDisplayDriver>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Settings;

namespace OrchardCore.Themes.Drivers;
namespace OrchardCore.Themes.TheAdmin.Drivers;

public sealed class ToggleThemeNavbarDisplayDriver : DisplayDriver<Navbar>
{
Expand All @@ -18,7 +18,6 @@ public override IDisplayResult Display(Navbar model, BuildDisplayContext context
{
return View("ToggleTheme", model)
.RenderWhen(async () => (await _siteService.GetSettingsAsync<AdminSettings>()).DisplayThemeToggler)
.Location("Detail", "Content:10")
.Location("DetailAdmin", "Content:10");
}
}
4 changes: 4 additions & 0 deletions src/OrchardCore.Themes/TheAdmin/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Admin.Models;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Html;
using OrchardCore.Environment.Shell.Configuration;
using OrchardCore.Modules;
using OrchardCore.Themes.TheAdmin.Drivers;

namespace OrchardCore.Themes.TheAdmin;

Expand All @@ -16,6 +19,7 @@ public Startup(IShellConfiguration configuration)

public override void ConfigureServices(IServiceCollection services)
{
services.AddDisplayDriver<Navbar, ToggleThemeNavbarDisplayDriver>();
services.AddResourceConfiguration<ResourceManagementOptionsConfiguration>();
services.Configure<TheAdminThemeOptions>(_configuration.GetSection("TheAdminTheme:StyleSettings"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using OrchardCore.Admin.Models;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Themes.Services;

namespace TheTheme.Drivers;

public sealed class ToggleThemeNavbarDisplayDriver : DisplayDriver<Navbar>
{
private readonly ISiteThemeService _siteThemeService;

public ToggleThemeNavbarDisplayDriver(ISiteThemeService siteThemeService)
{
_siteThemeService = siteThemeService;
}

public override IDisplayResult Display(Navbar model, BuildDisplayContext context)
{
return View("ToggleTheme", model)
.RenderWhen(async () => await _siteThemeService.GetSiteThemeNameAsync() == "TheTheme")
.Location("Detail", "Content:10");
}
}
6 changes: 5 additions & 1 deletion src/OrchardCore.Themes/TheTheme/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Admin.Models;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Modules;
using TheTheme.Drivers;

namespace OrchardCore.Themes.TheTheme;

public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection serviceCollection)
public override void ConfigureServices(IServiceCollection services)
{
services.AddDisplayDriver<Navbar, ToggleThemeNavbarDisplayDriver>();
}
}

0 comments on commit cebac22

Please sign in to comment.