#18769: Fixing menu import/export

Work Item: 18769

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros 2012-06-29 12:57:08 -07:00
parent cee5f3bb47
commit 5ca9b03741
10 changed files with 121 additions and 5 deletions

View File

@ -88,7 +88,8 @@ namespace Orchard.Core.Navigation.Drivers {
}
protected override void Exporting(MenuPart part, ContentManagement.Handlers.ExportContentContext context) {
var menuIdentity = _orchardServices.ContentManager.GetItemMetadata(_orchardServices.ContentManager.Get(part.Menu.Id)).Identity;
var menu = _orchardServices.ContentManager.Get(part.Menu.Id);
var menuIdentity = _orchardServices.ContentManager.GetItemMetadata(menu).Identity;
context.Element(part.PartDefinition.Name).SetAttributeValue("Menu", menuIdentity);
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText);

View File

@ -0,0 +1,39 @@
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Services;
using Orchard.Core.Title.Models;
namespace Orchard.Core.Navigation.Handlers {
[UsedImplicitly]
public class MenuHandler : ContentHandler {
private readonly IMenuService _menuService;
private readonly IContentManager _contentManager;
public MenuHandler(IMenuService menuService, IContentManager contentManager) {
_menuService = menuService;
_contentManager = contentManager;
}
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
if(context.ContentItem.ContentType != "Menu") {
return;
}
context.Metadata.Identity.Add("name", context.ContentItem.As<TitlePart>().Title);
}
protected override void Removing(RemoveContentContext context) {
if (context.ContentItem.ContentType != "Menu") {
return;
}
// remove all menu items
var menuParts = _menuService.GetMenuParts(context.ContentItem.Id);
foreach(var menuPart in menuParts) {
_contentManager.Remove(menuPart.ContentItem);
}
}
}
}

View File

@ -41,7 +41,6 @@ namespace Orchard.Core.Navigation {
ContentDefinitionManager.AlterTypeDefinition("Menu", cfg => cfg
.WithPart("CommonPart", p => p.WithSetting("OwnerEditorSettings.ShowOwnerEditor", "false"))
.WithPart("TitlePart")
.WithPart("Identity")
);
SchemaBuilder.CreateTable("MenuWidgetPartRecord", table => table
@ -123,7 +122,6 @@ namespace Orchard.Core.Navigation {
ContentDefinitionManager.AlterTypeDefinition("Menu", cfg => cfg
.WithPart("CommonPart")
.WithPart("TitlePart")
.WithPart("Identity")
);
SchemaBuilder.CreateTable("MenuWidgetPartRecord",table => table

View File

@ -7,4 +7,4 @@ OrchardVersion: 1.4.2
Description: The navigation module creates and manages a simple navigation menu for the front-end of the application and allows you to add content items to the admin menu.
FeatureDescription: Menu management.
Category: Core
FeatureDependencies: Orchard.ContentPicker
FeatureDependencies: Orchard.ContentPicker, Title

View File

@ -24,7 +24,7 @@
}
</select>
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
@Html.ActionLink(T("Edit").Text, "Edit", "Admin", new { area = "Contents", id = Model.CurrentMenu.Id, returnUrl = Request.RawUrl }, new { @class = "button" })
@Html.ActionLink(T("Edit").Text, "Edit", "Admin", new { area = "Contents", id = Model.CurrentMenu.Id, returnUrl = Url.Action("Index", "Admin", new { area = "Navigation" }) }, new { @class = "button" })
</fieldset>
}
}

View File

@ -0,0 +1,25 @@
@{
Model.Sidebar.Add(New.Menu_DeleteButton().ContentItem(Model.ContentItem), "25");
}
<div class="edit-item">
<div class="edit-item-primary">
@if (Model.Content != null) {
<div class="edit-item-content">
@Display(Model.Content)
</div>
}
</div>
<div class="edit-item-secondary group">
@if (Model.Actions != null) {
<div class="edit-item-actions">
@Display(Model.Actions)
</div>
}
@if (Model.Sidebar != null) {
<div class="edit-item-sidebar group">
@Display(Model.Sidebar)
</div>
}
</div>
</div>

View File

@ -0,0 +1,14 @@
@using Orchard.ContentManagement;
@using Orchard.Core.Contents
@using Orchard.Utility.Extensions;
@{
ContentItem contentItem = Model.ContentItem;
string returnUrl = Request["returnUrl"];
}
@if (Authorizer.Authorize(Permissions.DeleteContent, contentItem)) {
<fieldset class="delete-button">
@Html.Link(T("Delete").Text, Url.ItemRemoveUrl(contentItem, new {returnUrl}), new { @class = "button", itemprop = "RemoveUrl UnsafeUrl"})
</fieldset>
}

View File

@ -0,0 +1,26 @@
@{
Model.Sidebar.Add("Foo");
}
<div class="edit-item">
<div class="edit-item-primary">
@if (Model.Content != null) {
<div class="edit-item-content">
@Display(Model.Content)
</div>
}
</div>
<div class="edit-item-secondary group">
@if (Model.Actions != null) {
<div class="edit-item-actions">
@Display(Model.Actions)
</div>
}
@if (Model.Sidebar != null) {
<div class="edit-item-sidebar group">
@Display(Model.Sidebar)
</div>
}
</div>
</div>

View File

@ -136,6 +136,7 @@
<Compile Include="Navigation\Drivers\MenuWidgetPartDriver.cs" />
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
<Compile Include="Navigation\Handlers\ContentMenuItemPartHandler.cs" />
<Compile Include="Navigation\Handlers\MenuHandler.cs" />
<Compile Include="Navigation\Handlers\MenuWidgetPartHandler.cs" />
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
<Compile Include="Navigation\Models\AdminMenuPartRecord.cs" />
@ -545,6 +546,15 @@
<ItemGroup>
<Content Include="Navigation\Views\EditorTemplates\Parts.Navigation.Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\Content-Menu.Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\Menu.DeleteButton.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\Menu.Edit.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -71,6 +71,9 @@ namespace Orchard.ContentManagement {
dynamic itemShape = CreateItemShape(actualShapeType);
itemShape.ContentItem = content.ContentItem;
// adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
((IShape)itemShape).Metadata.Alternates.Add(actualShapeType + "__" + content.ContentItem.ContentType);
var context = new BuildEditorContext(itemShape, content, groupId, _shapeFactory);
BindPlacement(context, null, stereotype);