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:
Lombiq
2015-11-30 23:37:59 +01:00
parent c2dd09af5e
commit 0e1cca0fce
5 changed files with 116 additions and 6 deletions

View File

@@ -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);
}
}
}