mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Adding command to create a menu item.
Use the command in the default recipe files. Remove hardcoded home menu item creation from setup. --HG-- branch : recipe
This commit is contained in:
38
src/Orchard.Web/Core/Navigation/Commands/MenuCommands.cs
Normal file
38
src/Orchard.Web/Core/Navigation/Commands/MenuCommands.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Orchard.Commands;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
|
||||
namespace Orchard.Core.Navigation.Commands {
|
||||
public class MenuCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public MenuCommands(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
public string MenuPosition { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string MenuText { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string Url { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public bool OnMainMenu { get; set; }
|
||||
|
||||
[CommandName("menuitem create")]
|
||||
[CommandHelp("menuitem create /MenuPosition:<position> /MenuText:<text> /Url:<url> [/OnMainMenu:true|false]\r\n\t" + "Creates a new menu item")]
|
||||
[OrchardSwitches("MenuPosition,MenuText,Url,OnMainMenu")]
|
||||
public void Create() {
|
||||
var menuItem = _contentManager.Create("MenuItem");
|
||||
menuItem.As<MenuPart>().MenuPosition = MenuPosition;
|
||||
menuItem.As<MenuPart>().MenuText = T(MenuText).ToString();
|
||||
menuItem.As<MenuPart>().OnMainMenu = OnMainMenu;
|
||||
menuItem.As<MenuItemPart>().Url = Url;
|
||||
|
||||
Context.Output.WriteLine(T("Menu item created successfully.").Text);
|
||||
}
|
||||
}
|
||||
}
|
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Contents\Settings\ContentPartSettings.cs" />
|
||||
<Compile Include="Contents\Shapes.cs" />
|
||||
<Compile Include="Contents\ViewModels\PublishContentViewModel.cs" />
|
||||
<Compile Include="Navigation\Commands\MenuCommands.cs" />
|
||||
<Compile Include="Navigation\Services\MainMenuNavigationProvider.cs" />
|
||||
<Compile Include="Routable\Events\ISlugEventHandler.cs" />
|
||||
<Compile Include="Routable\ResourceManifest.cs" />
|
||||
|
@@ -89,7 +89,7 @@ Modules are created by other users of Orchard just like you so if you feel up to
|
||||
_contentManager.Publish(page);
|
||||
}
|
||||
|
||||
Context.Output.WriteLine(T("Page Created successfully.").Text);
|
||||
Context.Output.WriteLine(T("Page created successfully.").Text);
|
||||
}
|
||||
}
|
||||
}
|
@@ -45,6 +45,7 @@
|
||||
<Command>
|
||||
feature enable Orchard.Experimental.TestingLists
|
||||
page create /Slug:"welcome-to-orchard" /Title:"Welcome to Orchard!" /Path:"welcome-to-orchard" /Homepage:true /Publish:true /UseWelcomeText:true
|
||||
menuitem create /MenuPosition:"1" /MenuText:"Home" /Url:"" /OnMainMenu:true
|
||||
</Command>
|
||||
|
||||
<Migration features="*" />
|
||||
|
@@ -41,6 +41,7 @@
|
||||
<Command>
|
||||
feature enable Orchard.Experimental.TestingLists
|
||||
page create /Slug:"welcome-to-orchard" /Title:"Welcome to Orchard!" /Path:"welcome-to-orchard" /Homepage:true /Publish:true /UseWelcomeText:true
|
||||
menuitem create /MenuPosition:"1" /MenuText:"Home" /Url:"" /OnMainMenu:true
|
||||
</Command>
|
||||
|
||||
<Migration features="*" />
|
||||
|
@@ -41,6 +41,7 @@
|
||||
<Command>
|
||||
feature enable Orchard.Experimental.TestingLists
|
||||
page create /Slug:"welcome-to-orchard" /Title:"Welcome to Orchard!" /Path:"welcome-to-orchard" /Homepage:true /Publish:true /UseWelcomeText:true
|
||||
menuitem create /MenuPosition:"1" /MenuText:"Home" /Url:"" /OnMainMenu:true
|
||||
</Command>
|
||||
|
||||
<Migration features="*" />
|
||||
|
@@ -270,13 +270,6 @@ namespace Orchard.Setup.Services {
|
||||
contentManager.Publish(tripelThird);
|
||||
}
|
||||
|
||||
// add a menu item for the shiny new home page
|
||||
var menuItem = contentManager.Create("MenuItem");
|
||||
menuItem.As<MenuPart>().MenuPosition = "1";
|
||||
menuItem.As<MenuPart>().MenuText = T("Home").ToString();
|
||||
menuItem.As<MenuPart>().OnMainMenu = true;
|
||||
menuItem.As<MenuItemPart>().Url = "";
|
||||
|
||||
//null check: temporary fix for running setup in command line
|
||||
if (HttpContext.Current != null) {
|
||||
authenticationService.SignIn(user, true);
|
||||
|
Reference in New Issue
Block a user