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; }
|
||||
|
||||
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 feed = Shape.Feed()
|
||||
.FeedManager(_feedManager);
|
||||
|
@@ -72,8 +72,15 @@ namespace Orchard.Core.Routable.Handlers {
|
||||
public class RoutePartHandlerBase : ContentHandlerBase {
|
||||
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
var routable = context.ContentItem.As<RoutePart>();
|
||||
if (routable != null) {
|
||||
context.Metadata.DisplayText = routable.Title;
|
||||
|
||||
if (routable == null)
|
||||
return;
|
||||
|
||||
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 {
|
||||
{"Area", "Routable"},
|
||||
{"Controller", "Item"},
|
||||
|
@@ -10,13 +10,16 @@ namespace Orchard.Core.Routable.Services {
|
||||
[UsedImplicitly]
|
||||
public class RoutableHomePageProvider : IHomePageProvider {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
public const string Name = "RoutableHomePageProvider";
|
||||
|
||||
public RoutableHomePageProvider(
|
||||
IOrchardServices services,
|
||||
IContentManager contentManager,
|
||||
IShapeFactory shapeFactory) {
|
||||
IShapeFactory shapeFactory,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_contentManager = contentManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
Services = services;
|
||||
T = NullLocalizer.Instance;
|
||||
Shape = shapeFactory;
|
||||
@@ -39,11 +42,13 @@ namespace Orchard.Core.Routable.Services {
|
||||
if (contentItem == null || !contentItem.Is<RoutePart>())
|
||||
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",
|
||||
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.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Blogs.Handlers {
|
||||
@@ -23,6 +24,12 @@ namespace Orchard.Blogs.Handlers {
|
||||
if (blog == null)
|
||||
return;
|
||||
|
||||
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "Blog"},
|
||||
{"Action", "Item"},
|
||||
{"blogSlug", blog.As<RoutePart>().Slug}
|
||||
};
|
||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "BlogAdmin"},
|
||||
|
@@ -9,13 +9,10 @@ namespace Orchard.Mvc.Html {
|
||||
/// <see cref="http://en.wikipedia.org/wiki/Harry_Houdini"/>
|
||||
/// <returns>himself</returns>
|
||||
public static TService Resolve<TService>(this HtmlHelper html) {
|
||||
var workContextAccessor = html.ViewContext.RouteData.DataTokens["IWorkContextAccessor"] as IWorkContextAccessor;
|
||||
if (workContextAccessor == null)
|
||||
throw new ApplicationException("Unable to resolve");
|
||||
var workContext = html.ViewContext.RequestContext.GetWorkContext();
|
||||
|
||||
var workContext = workContextAccessor.GetContext(html.ViewContext.HttpContext);
|
||||
if (workContext == null)
|
||||
throw new ApplicationException("Unable to resolve");
|
||||
return default(TService);
|
||||
|
||||
return workContext.Resolve<TService>();
|
||||
}
|
||||
|
@@ -21,6 +21,10 @@ namespace Orchard.UI.Navigation {
|
||||
}
|
||||
|
||||
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 menuName = "main";
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Mvc.Filters;
|
||||
@@ -20,6 +19,10 @@ namespace Orchard.UI.Resources {
|
||||
|
||||
|
||||
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 head = ctx.Layout.Head;
|
||||
var tail = ctx.Layout.Tail;
|
||||
|
@@ -10,27 +10,48 @@ namespace Orchard {
|
||||
}
|
||||
|
||||
public static WorkContext GetWorkContext(this RequestContext requestContext) {
|
||||
if (requestContext == null) {
|
||||
if (requestContext == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
var routeData = requestContext.RouteData;
|
||||
object value;
|
||||
if (routeData == null ||
|
||||
routeData.DataTokens == null ||
|
||||
!routeData.DataTokens.TryGetValue("IWorkContextAccessor", out value) ||
|
||||
!(value is IWorkContextAccessor)) {
|
||||
if (routeData == null || routeData.DataTokens == 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);
|
||||
}
|
||||
|
||||
public static WorkContext GetWorkContext(this ControllerContext controllerContext) {
|
||||
if (controllerContext == null) {
|
||||
private static object FindWorkContextInParent(RouteData routeData) {
|
||||
object parentViewContextValue;
|
||||
if (!routeData.DataTokens.TryGetValue("ParentActionViewContext", out parentViewContextValue)
|
||||
|| !(parentViewContextValue is ViewContext)) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user