mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-27 12:29:04 +08:00
Improving how dependencies for themes are handled: enabling dependencies (modules) for themes too, handling this also when themes are just previewed and disabling themes when their dependencies are disabled.
Fixes the tightly connected following issues: #4336, #5004, #4667
This commit is contained in:
@@ -37,6 +37,8 @@ namespace Orchard.Themes.Controllers {
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
||||
private const string AlreadyEnabledFeatures = "Orchard.Themes.AlreadyEnabledFeatures";
|
||||
|
||||
public AdminController(
|
||||
IEnumerable<IExtensionDisplayEventHandler> extensionDisplayEventHandlers,
|
||||
IOrchardServices services,
|
||||
@@ -136,8 +138,11 @@ namespace Orchard.Themes.Controllers {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeId));
|
||||
} else {
|
||||
var alreadyEnabledFeatures = GetEnabledFeatures();
|
||||
_themeService.EnableThemeFeatures(themeId);
|
||||
_previewTheme.SetPreviewTheme(themeId);
|
||||
alreadyEnabledFeatures.Except(new[] { themeId });
|
||||
TempData[AlreadyEnabledFeatures] = alreadyEnabledFeatures;
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, "~/");
|
||||
@@ -165,6 +170,18 @@ namespace Orchard.Themes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (TempData.ContainsKey(AlreadyEnabledFeatures)) {
|
||||
|
||||
var alreadyEnabledFeatures = TempData[AlreadyEnabledFeatures] as IEnumerable<string>;
|
||||
if (alreadyEnabledFeatures != null) {
|
||||
var afterEnabledFeatures = GetEnabledFeatures();
|
||||
if (afterEnabledFeatures.Count() > alreadyEnabledFeatures.Count()) {
|
||||
var disableFeatures = afterEnabledFeatures.Except(alreadyEnabledFeatures);
|
||||
_themeService.DisablePreviewFeatures(disableFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
@@ -256,5 +273,9 @@ namespace Orchard.Themes.Controllers {
|
||||
return string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetEnabledFeatures() {
|
||||
return _featureManager.GetEnabledFeatures().Select(f => f.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user