mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -21,6 +21,10 @@ namespace Orchard.Core.Feeds.Services {
|
|||||||
dynamic Shape { get; set; }
|
dynamic Shape { get; set; }
|
||||||
|
|
||||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||||
|
// should only run on a full view rendering result
|
||||||
|
if (!(filterContext.Result is ViewResult))
|
||||||
|
return;
|
||||||
|
|
||||||
var layout = _workContextAccessor.GetContext(filterContext).Layout;
|
var layout = _workContextAccessor.GetContext(filterContext).Layout;
|
||||||
var feed = Shape.Feed()
|
var feed = Shape.Feed()
|
||||||
.FeedManager(_feedManager);
|
.FeedManager(_feedManager);
|
||||||
|
@@ -72,8 +72,15 @@ namespace Orchard.Core.Routable.Handlers {
|
|||||||
public class RoutePartHandlerBase : ContentHandlerBase {
|
public class RoutePartHandlerBase : ContentHandlerBase {
|
||||||
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||||
var routable = context.ContentItem.As<RoutePart>();
|
var routable = context.ContentItem.As<RoutePart>();
|
||||||
if (routable != null) {
|
|
||||||
|
if (routable == null)
|
||||||
|
return;
|
||||||
|
|
||||||
context.Metadata.DisplayText = routable.Title;
|
context.Metadata.DisplayText = routable.Title;
|
||||||
|
|
||||||
|
// 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 implemntation
|
||||||
|
if (context.Metadata.DisplayRouteValues == null || context.Metadata.DisplayRouteValues["Area"] as string == "Contents") {
|
||||||
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
||||||
{"Area", "Routable"},
|
{"Area", "Routable"},
|
||||||
{"Controller", "Item"},
|
{"Controller", "Item"},
|
||||||
|
@@ -10,13 +10,16 @@ namespace Orchard.Core.Routable.Services {
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class RoutableHomePageProvider : IHomePageProvider {
|
public class RoutableHomePageProvider : IHomePageProvider {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
public const string Name = "RoutableHomePageProvider";
|
public const string Name = "RoutableHomePageProvider";
|
||||||
|
|
||||||
public RoutableHomePageProvider(
|
public RoutableHomePageProvider(
|
||||||
IOrchardServices services,
|
IOrchardServices services,
|
||||||
IContentManager contentManager,
|
IContentManager contentManager,
|
||||||
IShapeFactory shapeFactory) {
|
IShapeFactory shapeFactory,
|
||||||
|
IWorkContextAccessor workContextAccessor) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_workContextAccessor = workContextAccessor;
|
||||||
Services = services;
|
Services = services;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Shape = shapeFactory;
|
Shape = shapeFactory;
|
||||||
@@ -39,11 +42,13 @@ namespace Orchard.Core.Routable.Services {
|
|||||||
if (contentItem == null || !contentItem.Is<RoutePart>())
|
if (contentItem == null || !contentItem.Is<RoutePart>())
|
||||||
return new HttpNotFoundResult();
|
return new HttpNotFoundResult();
|
||||||
|
|
||||||
var model = _contentManager.BuildDisplay(contentItem);
|
// get the display metadata for the home page item
|
||||||
|
var displayRouteValues = _contentManager.GetItemMetadata(contentItem).DisplayRouteValues;
|
||||||
|
|
||||||
return new ViewResult {
|
var model = Shape.ViewModel(RouteValues: displayRouteValues);
|
||||||
|
return new PartialViewResult {
|
||||||
ViewName = "Routable.HomePage",
|
ViewName = "Routable.HomePage",
|
||||||
ViewData = new ViewDataDictionary<dynamic>(model)
|
ViewData = new ViewDataDictionary<object>(model)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1,4 @@
|
|||||||
@Display(Model)
|
@{
|
||||||
|
RouteValueDictionary routeValues = Model.RouteValues;
|
||||||
|
Html.RenderAction(routeValues["action"] as string, routeValues["controller"] as string, routeValues);
|
||||||
|
}
|
@@ -3,6 +3,7 @@ using JetBrains.Annotations;
|
|||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Core.Routable.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Handlers {
|
namespace Orchard.Blogs.Handlers {
|
||||||
@@ -23,6 +24,12 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
if (blog == null)
|
if (blog == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
||||||
|
{"Area", "Orchard.Blogs"},
|
||||||
|
{"Controller", "Blog"},
|
||||||
|
{"Action", "Item"},
|
||||||
|
{"blogSlug", blog.As<RoutePart>().Slug}
|
||||||
|
};
|
||||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||||
{"Area", "Orchard.Blogs"},
|
{"Area", "Orchard.Blogs"},
|
||||||
{"Controller", "BlogAdmin"},
|
{"Controller", "BlogAdmin"},
|
||||||
|
@@ -9,13 +9,10 @@ namespace Orchard.Mvc.Html {
|
|||||||
/// <see cref="http://en.wikipedia.org/wiki/Harry_Houdini"/>
|
/// <see cref="http://en.wikipedia.org/wiki/Harry_Houdini"/>
|
||||||
/// <returns>himself</returns>
|
/// <returns>himself</returns>
|
||||||
public static TService Resolve<TService>(this HtmlHelper html) {
|
public static TService Resolve<TService>(this HtmlHelper html) {
|
||||||
var workContextAccessor = html.ViewContext.RouteData.DataTokens["IWorkContextAccessor"] as IWorkContextAccessor;
|
var workContext = html.ViewContext.RequestContext.GetWorkContext();
|
||||||
if (workContextAccessor == null)
|
|
||||||
throw new ApplicationException("Unable to resolve");
|
|
||||||
|
|
||||||
var workContext = workContextAccessor.GetContext(html.ViewContext.HttpContext);
|
|
||||||
if (workContext == null)
|
if (workContext == null)
|
||||||
throw new ApplicationException("Unable to resolve");
|
return default(TService);
|
||||||
|
|
||||||
return workContext.Resolve<TService>();
|
return workContext.Resolve<TService>();
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,10 @@ namespace Orchard.UI.Navigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||||
|
// should only run on a full view rendering result
|
||||||
|
if (!(filterContext.Result is ViewResult))
|
||||||
|
return;
|
||||||
|
|
||||||
var workContext = _workContextAccessor.GetContext(filterContext);
|
var workContext = _workContextAccessor.GetContext(filterContext);
|
||||||
|
|
||||||
var menuName = "main";
|
var menuName = "main";
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Mvc.Filters;
|
using Orchard.Mvc.Filters;
|
||||||
@@ -20,6 +19,10 @@ namespace Orchard.UI.Resources {
|
|||||||
|
|
||||||
|
|
||||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||||
|
// should only run on a full view rendering result
|
||||||
|
if (!(filterContext.Result is ViewResult))
|
||||||
|
return;
|
||||||
|
|
||||||
var ctx = _workContextAccessor.GetContext();
|
var ctx = _workContextAccessor.GetContext();
|
||||||
var head = ctx.Layout.Head;
|
var head = ctx.Layout.Head;
|
||||||
var tail = ctx.Layout.Tail;
|
var tail = ctx.Layout.Tail;
|
||||||
|
@@ -10,27 +10,48 @@ namespace Orchard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static WorkContext GetWorkContext(this RequestContext requestContext) {
|
public static WorkContext GetWorkContext(this RequestContext requestContext) {
|
||||||
if (requestContext == null) {
|
if (requestContext == null)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
var routeData = requestContext.RouteData;
|
var routeData = requestContext.RouteData;
|
||||||
object value;
|
if (routeData == null || routeData.DataTokens == null)
|
||||||
if (routeData == null ||
|
|
||||||
routeData.DataTokens == null ||
|
|
||||||
!routeData.DataTokens.TryGetValue("IWorkContextAccessor", out value) ||
|
|
||||||
!(value is IWorkContextAccessor)) {
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
object workContextValue;
|
||||||
|
if (!routeData.DataTokens.TryGetValue("IWorkContextAccessor", out workContextValue)) {
|
||||||
|
workContextValue = FindWorkContextInParent(routeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
var workContextAccessor = (IWorkContextAccessor)value;
|
if (!(workContextValue is IWorkContextAccessor))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var workContextAccessor = (IWorkContextAccessor)workContextValue;
|
||||||
return workContextAccessor.GetContext(requestContext.HttpContext);
|
return workContextAccessor.GetContext(requestContext.HttpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorkContext GetWorkContext(this ControllerContext controllerContext) {
|
private static object FindWorkContextInParent(RouteData routeData) {
|
||||||
if (controllerContext == null) {
|
object parentViewContextValue;
|
||||||
|
if (!routeData.DataTokens.TryGetValue("ParentActionViewContext", out parentViewContextValue)
|
||||||
|
|| !(parentViewContextValue is ViewContext)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var parentRouteData = ((ViewContext)parentViewContextValue).RouteData;
|
||||||
|
if (parentRouteData == null || parentRouteData.DataTokens == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
object workContextValue;
|
||||||
|
if (!parentRouteData.DataTokens.TryGetValue("IWorkContextAccessor", out workContextValue)) {
|
||||||
|
workContextValue = FindWorkContextInParent(parentRouteData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return workContextValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorkContext GetWorkContext(this ControllerContext controllerContext) {
|
||||||
|
if (controllerContext == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
return WorkContextExtensions.GetWorkContext(controllerContext.RequestContext);
|
return WorkContextExtensions.GetWorkContext(controllerContext.RequestContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user