mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Remove Routable dependency on IHomePageProvider
--HG-- branch : autoroute
This commit is contained in:
@@ -18,16 +18,13 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IRoutableService _routableService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IHomePageProvider _routableHomePageProvider;
|
||||
|
||||
public RoutePartDriver(IOrchardServices services,
|
||||
IRoutableService routableService,
|
||||
IEnumerable<IHomePageProvider> homePageProviders,
|
||||
IHttpContextAccessor httpContextAccessor) {
|
||||
_services = services;
|
||||
_routableService = routableService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -71,7 +68,6 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
var containerUrl = new UriBuilder(request.ToRootUrlString()) { Path = (request.ApplicationPath ?? "").TrimEnd('/') + "/" + (part.GetContainerPath() ?? "") };
|
||||
model.ContainerAbsoluteUrl = containerUrl.Uri.ToString().TrimEnd('/');
|
||||
|
||||
model.PromoteToHomePage = model.Id != 0 && _routableHomePageProvider != null && _services.WorkContext.CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
|
||||
return ContentShape("Parts_Routable_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||
}
|
||||
@@ -111,22 +107,12 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
part.Path = path;
|
||||
}
|
||||
|
||||
var promoteToHomePage = context.Attribute(part.PartDefinition.Name, "PromoteToHomePage");
|
||||
if (promoteToHomePage != null) {
|
||||
part.PromoteToHomePage = Convert.ToBoolean(promoteToHomePage);
|
||||
if (part.PromoteToHomePage && _routableHomePageProvider != null) {
|
||||
_services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(RoutePart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Title", part.Title);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Slug", part.Slug);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Path", part.Path);
|
||||
if (_services.WorkContext.CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(part.ContentItem.Id)) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", "true");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
private readonly IRoutableService _routableService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IHomePageProvider _routableHomePageProvider;
|
||||
|
||||
public RoutePartHandler(
|
||||
IOrchardServices services,
|
||||
@@ -26,14 +25,12 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
IRoutablePathConstraint routablePathConstraint,
|
||||
IRoutableService routableService,
|
||||
IContentManager contentManager,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IEnumerable<IHomePageProvider> homePageProviders) {
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_services = services;
|
||||
_routablePathConstraint = routablePathConstraint;
|
||||
_routableService = routableService;
|
||||
_contentManager = contentManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
||||
T = NullLocalizer.Instance;
|
||||
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
@@ -51,32 +48,6 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
|
||||
Action<PublishContentContext, RoutePart> handler = (context, route) => {
|
||||
FinalizePath(route, context, processSlug);
|
||||
|
||||
if (_routableHomePageProvider == null)
|
||||
return;
|
||||
|
||||
var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage;
|
||||
var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting)
|
||||
? _routableHomePageProvider.GetHomePageId(homePageSetting)
|
||||
: 0;
|
||||
|
||||
if (route.Id != 0 && (route.Id == currentHomePageId || route.PromoteToHomePage)) {
|
||||
|
||||
if (currentHomePageId != route.Id) {
|
||||
// reset the path on the current home page
|
||||
var currentHomePage = _contentManager.Get(currentHomePageId);
|
||||
if (currentHomePage != null)
|
||||
FinalizePath(currentHomePage.As<RoutePart>(), context, processSlug);
|
||||
// set the new home page
|
||||
_services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(route.ContentItem.Id);
|
||||
}
|
||||
|
||||
// readjust the constraints of the current current home page
|
||||
_routablePathConstraint.RemovePath(route.Path);
|
||||
route.Path = "";
|
||||
_routableService.FixContainedPaths(route);
|
||||
_routablePathConstraint.AddPath(route.Path);
|
||||
}
|
||||
};
|
||||
|
||||
OnPublished<RoutePart>(handler);
|
||||
@@ -128,11 +99,9 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
|
||||
public class RoutePartHandlerBase : ContentHandlerBase {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IHomePageProvider _routableHomePageProvider;
|
||||
|
||||
public RoutePartHandlerBase(IWorkContextAccessor workContextAccessor, IEnumerable<IHomePageProvider> homePageProviders) {
|
||||
public RoutePartHandlerBase(IWorkContextAccessor workContextAccessor) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
||||
}
|
||||
|
||||
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
@@ -144,9 +113,7 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
// set the display route values if it hasn't been set or only has been set by the Contents module.
|
||||
// allows other modules to set their own display. probably not common enough to warrant some priority implementation
|
||||
if (context.Metadata.DisplayRouteValues == null || context.Metadata.DisplayRouteValues["Area"] as string == "Contents") {
|
||||
var itemPath = routable.Id == _routableHomePageProvider.GetHomePageId(_workContextAccessor.GetContext().CurrentSite.HomePage)
|
||||
? ""
|
||||
: routable.Path;
|
||||
var itemPath = routable.Path;
|
||||
|
||||
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Routable"},
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Services;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Routable.Services {
|
||||
[UsedImplicitly]
|
||||
public class RoutableHomePageProvider : IHomePageProvider {
|
||||
private readonly IContentManager _contentManager;
|
||||
public const string Name = "RoutableHomePageProvider";
|
||||
|
||||
public RoutableHomePageProvider(
|
||||
IContentManager contentManager,
|
||||
IShapeFactory shapeFactory) {
|
||||
_contentManager = contentManager;
|
||||
Shape = shapeFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
dynamic Shape { get; set; }
|
||||
|
||||
public string GetProviderName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string GetSettingValue(int id) {
|
||||
return GetProviderName() + ";" + id;
|
||||
}
|
||||
|
||||
public int GetHomePageId(string value) {
|
||||
int id;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value) || !int.TryParse(value.Substring(Name.Length + 1), out id))
|
||||
throw new ApplicationException(T("Invalid home page setting value for {0}: {1}", Name, value).Text);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public ActionResult GetHomePage(int id) {
|
||||
var contentItem = _contentManager.Get(id, VersionOptions.Published);
|
||||
if (contentItem == null || !contentItem.Is<RoutePart>())
|
||||
return new HttpNotFoundResult();
|
||||
|
||||
// get the display metadata for the home page item
|
||||
var displayRouteValues = _contentManager.GetItemMetadata(contentItem).DisplayRouteValues;
|
||||
|
||||
var model = Shape.ViewModel(RouteValues: displayRouteValues);
|
||||
return new PartialViewResult {
|
||||
ViewName = "Routable.HomePage",
|
||||
ViewData = new ViewDataDictionary<object>(model)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
@{
|
||||
RouteValueDictionary routeValues = Model.RouteValues;
|
||||
Html.RenderAction(routeValues["action"] as string, routeValues["controller"] as string, routeValues);
|
||||
}
|
||||
Reference in New Issue
Block a user