mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00

- 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
47 lines
1.6 KiB
C#
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)
|
|
};
|
|
}
|
|
}
|
|
}
|