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
This commit is contained in:
Nathan Heskew
2010-11-25 22:10:07 -08:00
parent b532569eb4
commit 79fbacf0b6
7 changed files with 41 additions and 8 deletions

View File

@@ -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);

View File

@@ -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) {
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 { context.Metadata.DisplayRouteValues = new RouteValueDictionary {
{"Area", "Routable"}, {"Area", "Routable"},
{"Controller", "Item"}, {"Controller", "Item"},

View File

@@ -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)
}; };
} }
} }

View File

@@ -1 +1,4 @@
@Display(Model) @{
RouteValueDictionary routeValues = Model.RouteValues;
Html.RenderAction(routeValues["action"] as string, routeValues["controller"] as string, routeValues);
}

View File

@@ -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"},

View File

@@ -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";

View File

@@ -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;