mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Merge pull request #6139 from neTp9c/ImportExportMenuElement
Import and Export for menu element.
This commit is contained in:
commit
cb572e0bed
@ -9,6 +9,7 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Layouts.Elements;
|
||||
using Orchard.Layouts.Framework.Display;
|
||||
using Orchard.Layouts.Framework.Drivers;
|
||||
using Orchard.Layouts.Helpers;
|
||||
using Orchard.Layouts.ViewModels;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Utility.Extensions;
|
||||
@ -19,11 +20,18 @@ namespace Orchard.Layouts.Drivers {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IMenuService _menuService;
|
||||
private readonly INavigationManager _navigationManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public MenuElementDriver(IMenuService menuService, INavigationManager navigationManager, IWorkContextAccessor workContextAccessor, IShapeFactory shapeFactory) {
|
||||
public MenuElementDriver(
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IMenuService menuService,
|
||||
INavigationManager navigationManager,
|
||||
IContentManager contentManager,
|
||||
IShapeFactory shapeFactory) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_menuService = menuService;
|
||||
_navigationManager = navigationManager;
|
||||
_contentManager = contentManager;
|
||||
New = shapeFactory;
|
||||
}
|
||||
|
||||
@ -124,5 +132,23 @@ namespace Orchard.Layouts.Drivers {
|
||||
|
||||
context.ElementShape.Menu = menuShape;
|
||||
}
|
||||
|
||||
protected override void OnExporting(Menu element, ExportElementContext context) {
|
||||
var menu = _contentManager.Get(element.MenuContentItemId);
|
||||
var menuIdentity = menu != null ? _contentManager.GetItemMetadata(menu).Identity.ToString() : default(string);
|
||||
|
||||
if (menuIdentity != null)
|
||||
context.ExportableData["MenuId"] = menuIdentity;
|
||||
}
|
||||
|
||||
protected override void OnImporting(Menu element, ImportElementContext context) {
|
||||
var menuIdentity = context.ExportableData.Get("MenuId");
|
||||
var menu = menuIdentity != null ? context.Session.GetItemFromSession(menuIdentity) : default(ContentManagement.ContentItem);
|
||||
|
||||
if (menu == null)
|
||||
return;
|
||||
|
||||
element.MenuContentItemId = menu.Id;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user