From 79fbacf0b683772aaa0a9cdc19dcf1318bd6a755 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Thu, 25 Nov 2010 22:10:07 -0800 Subject: [PATCH] Updating the RoutableHomePageProvider to use the relevant display action for the given content item. This lets unique display actions, like Blog/Item, do their own thing. In the case of the blog, its posts are once again showing up on the home page. The routing problem (where the home page'd item still is seen as having its own path) still needs to be fixed so the item on the home page can't be hit at different URLs (and so something like paging works on the home page) work item: 16720 --HG-- branch : dev --- src/Orchard.Web/Core/Feeds/Services/FeedFilter.cs | 4 ++++ .../Core/Routable/Handlers/RoutePartHandler.cs | 11 +++++++++-- .../Routable/Services/RoutableHomePageProvider.cs | 13 +++++++++---- .../Core/Routable/Views/Routable.HomePage.cshtml | 5 ++++- .../Orchard.Blogs/Handlers/BlogPartHandler.cs | 7 +++++++ src/Orchard/UI/Navigation/MenuFilter.cs | 4 ++++ src/Orchard/UI/Resources/ResourceFilter.cs | 5 ++++- 7 files changed, 41 insertions(+), 8 deletions(-) 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/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;