diff --git a/src/Orchard.Web/Core/Feeds/Services/FeedFilter.cs b/src/Orchard.Web/Core/Feeds/Services/FeedFilter.cs index 5af31c66c..0fc6f9621 100644 --- a/src/Orchard.Web/Core/Feeds/Services/FeedFilter.cs +++ b/src/Orchard.Web/Core/Feeds/Services/FeedFilter.cs @@ -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); diff --git a/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs b/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs index 7e7ba858b..6e70fa72d 100644 --- a/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs +++ b/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs @@ -72,8 +72,15 @@ namespace Orchard.Core.Routable.Handlers { public class RoutePartHandlerBase : ContentHandlerBase { public override void GetContentItemMetadata(GetContentItemMetadataContext context) { var routable = context.ContentItem.As(); - 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"}, diff --git a/src/Orchard.Web/Core/Routable/Services/RoutableHomePageProvider.cs b/src/Orchard.Web/Core/Routable/Services/RoutableHomePageProvider.cs index 18bd86f49..bf43531b5 100644 --- a/src/Orchard.Web/Core/Routable/Services/RoutableHomePageProvider.cs +++ b/src/Orchard.Web/Core/Routable/Services/RoutableHomePageProvider.cs @@ -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()) 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(model) + ViewData = new ViewDataDictionary(model) }; } } diff --git a/src/Orchard.Web/Core/Routable/Views/Routable.HomePage.cshtml b/src/Orchard.Web/Core/Routable/Views/Routable.HomePage.cshtml index 631e9eb0f..594797276 100644 --- a/src/Orchard.Web/Core/Routable/Views/Routable.HomePage.cshtml +++ b/src/Orchard.Web/Core/Routable/Views/Routable.HomePage.cshtml @@ -1 +1,4 @@ -@Display(Model) \ No newline at end of file +@{ + RouteValueDictionary routeValues = Model.RouteValues; + Html.RenderAction(routeValues["action"] as string, routeValues["controller"] as string, routeValues); +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs index 23c9b6693..afbb78849 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs @@ -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().Slug} + }; context.Metadata.CreateRouteValues = new RouteValueDictionary { {"Area", "Orchard.Blogs"}, {"Controller", "BlogAdmin"}, diff --git a/src/Orchard/Mvc/Html/ContainerExtensions.cs b/src/Orchard/Mvc/Html/ContainerExtensions.cs index 0e104904d..035947e99 100644 --- a/src/Orchard/Mvc/Html/ContainerExtensions.cs +++ b/src/Orchard/Mvc/Html/ContainerExtensions.cs @@ -9,13 +9,10 @@ namespace Orchard.Mvc.Html { /// /// himself public static TService Resolve(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(); } diff --git a/src/Orchard/UI/Navigation/MenuFilter.cs b/src/Orchard/UI/Navigation/MenuFilter.cs index 6e2a80875..4027305c1 100644 --- a/src/Orchard/UI/Navigation/MenuFilter.cs +++ b/src/Orchard/UI/Navigation/MenuFilter.cs @@ -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"; diff --git a/src/Orchard/UI/Resources/ResourceFilter.cs b/src/Orchard/UI/Resources/ResourceFilter.cs index 72148a1b2..990184f1b 100644 --- a/src/Orchard/UI/Resources/ResourceFilter.cs +++ b/src/Orchard/UI/Resources/ResourceFilter.cs @@ -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; diff --git a/src/Orchard/WorkContextExtensions.cs b/src/Orchard/WorkContextExtensions.cs index 3b4956805..1c1b6d690 100644 --- a/src/Orchard/WorkContextExtensions.cs +++ b/src/Orchard/WorkContextExtensions.cs @@ -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); }