mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
- Ability to promote cms pages to be homepage.
- New homepage core package with a home controller and routes. Home->Index action calls homepage provider, implemented by pages package. - New site setting (invisible), which is the currently active homepage provider + a parameter identifies the "item" within the provider. - Add checkbox to Edit Page form to set the page being edited to be homepage. --HG-- branch : dev
This commit is contained in:
56
src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs
Normal file
56
src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Core.HomePage.Controllers {
|
||||
[HandleError]
|
||||
public class HomeController : Controller {
|
||||
private readonly IEnumerable<IHomePageProvider> _homePageProviders;
|
||||
|
||||
public HomeController(IEnumerable<IHomePageProvider> homePageProviders) {
|
||||
_homePageProviders = homePageProviders;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
string homepage = CurrentSite.HomePage;
|
||||
if (String.IsNullOrEmpty(homepage)) {
|
||||
return View(new BaseViewModel());
|
||||
}
|
||||
|
||||
string[] homePageParameters = homepage.Split(';');
|
||||
if (homePageParameters.Length != 2) {
|
||||
return View(new BaseViewModel());
|
||||
}
|
||||
string providerName = homePageParameters[0];
|
||||
int item = Int32.Parse(homePageParameters[1]);
|
||||
|
||||
foreach (var provider in _homePageProviders) {
|
||||
if (String.Equals(provider.GetProviderName(), providerName)) {
|
||||
ActionResult result = provider.GetHomePage(item);
|
||||
if (result is ViewResultBase) {
|
||||
ViewResultBase resultBase = result as ViewResultBase;
|
||||
ViewData = resultBase.ViewData;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return View(new BaseViewModel());
|
||||
}
|
||||
catch {
|
||||
return View(new BaseViewModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1
src/Orchard.Web/Core/HomePage/Module.txt
Normal file
1
src/Orchard.Web/Core/HomePage/Module.txt
Normal file
@@ -0,0 +1 @@
|
||||
name: HomePage
|
36
src/Orchard.Web/Core/HomePage/Routes.cs
Normal file
36
src/Orchard.Web/Core/HomePage/Routes.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Mvc.Routes;
|
||||
|
||||
namespace Orchard.Core.HomePage {
|
||||
public class Routes : IRouteProvider {
|
||||
public void GetRoutes(ICollection<RouteDescriptor> routes) {
|
||||
foreach (var routeDescriptor in GetRoutes())
|
||||
routes.Add(routeDescriptor);
|
||||
}
|
||||
|
||||
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Priority = 20,
|
||||
Route = new Route(
|
||||
"",
|
||||
new RouteValueDictionary {
|
||||
{"area", "HomePage"},
|
||||
{"controller", "Home"},
|
||||
{"action", "Index"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "HomePage"},
|
||||
{"controller", "Home"},
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "HomePage"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -102,6 +102,8 @@
|
||||
<Compile Include="Feeds\Models\FeedResponse.cs" />
|
||||
<Compile Include="Feeds\Rss\RssFeedBuilder.cs" />
|
||||
<Compile Include="Feeds\Rss\RssResult.cs" />
|
||||
<Compile Include="HomePage\Controllers\HomeController.cs" />
|
||||
<Compile Include="HomePage\Routes.cs" />
|
||||
<Compile Include="Navigation\AdminMenu.cs" />
|
||||
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
||||
<Compile Include="Navigation\Models\MenuItem.cs" />
|
||||
@@ -216,6 +218,7 @@
|
||||
<Content Include="Themes\Views\Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="HomePage\Module.txt" />
|
||||
<Content Include="Navigation\Views\Admin\Index.ascx" />
|
||||
<Content Include="Navigation\Views\EditorTemplates\Parts\Navigation.EditMenuPart.ascx" />
|
||||
<Content Include="Navigation\Views\Web.config" />
|
||||
|
@@ -24,5 +24,9 @@ namespace Orchard.Core.Settings.Models {
|
||||
get { return Record.SuperUser; }
|
||||
set { Record.SuperUser = value; }
|
||||
}
|
||||
public string HomePage {
|
||||
get { return Record.HomePage; }
|
||||
set { Record.HomePage = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,5 +7,6 @@ namespace Orchard.Core.Settings.Records {
|
||||
public virtual string SiteName { get; set; }
|
||||
public virtual string SuperUser { get; set; }
|
||||
public virtual string PageTitleSeparator { get; set; }
|
||||
public virtual string HomePage { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user