Files
Orchard/src/Orchard.Web/Core/Routable/Services/RoutableHomePageProvider.cs
Nathan Heskew 902769569f Fixing up the RoutePart so a page that is set to be the home page only becomes the home page if the page is published
- previously if the page wasn't immediately published (saved as draft or scheduled for later publishing) it still overrode the home page setting and the home page subsequently became a nice 404 page

--HG--
branch : dev
2010-11-30 14:02:26 -08:00

47 lines
1.6 KiB
C#

using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Core.Routable.Models;
using Orchard.DisplayManagement;
using Orchard.Services;
using Orchard.ContentManagement;
namespace Orchard.Core.Routable.Services {
[UsedImplicitly]
public class RoutableHomePageProvider : IHomePageProvider {
private readonly IContentManager _contentManager;
public const string Name = "RoutableHomePageProvider";
public RoutableHomePageProvider(
IContentManager contentManager,
IShapeFactory shapeFactory) {
_contentManager = contentManager;
Shape = shapeFactory;
}
dynamic Shape { get; set; }
public string GetProviderName() {
return Name;
}
public string GetSettingValue(int id) {
return GetProviderName() + ";" + id;
}
public ActionResult GetHomePage(int id) {
var contentItem = _contentManager.Get(id, VersionOptions.Published);
if (contentItem == null || !contentItem.Is<RoutePart>())
return new HttpNotFoundResult();
// get the display metadata for the home page item
var displayRouteValues = _contentManager.GetItemMetadata(contentItem).DisplayRouteValues;
var model = Shape.ViewModel(RouteValues: displayRouteValues);
return new PartialViewResult {
ViewName = "Routable.HomePage",
ViewData = new ViewDataDictionary<object>(model)
};
}
}
}