mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
@@ -104,11 +105,14 @@ namespace Orchard.Layouts.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(LayoutPart part, ImportContentContext context) {
|
||||
part.LayoutState = context.Data.Element(part.PartDefinition.Name).El("LayoutState");
|
||||
_layoutManager.Importing(new ImportLayoutContext {
|
||||
Layout = part,
|
||||
Session = new ImportContentContextWrapper(context)
|
||||
context.ImportChildEl(part.PartDefinition.Name, "LayoutState", s => {
|
||||
part.LayoutState = s;
|
||||
_layoutManager.Importing(new ImportLayoutContext {
|
||||
Layout = part,
|
||||
Session = new ImportContentContextWrapper(context)
|
||||
});
|
||||
});
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "TemplateId", s => part.TemplateId = GetTemplateId(context, s));
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,6 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
public XElement Data { get; set; }
|
||||
private ImportContentSession Session { get; set; }
|
||||
|
||||
|
||||
public ImportContentContext(ContentItem contentItem, XElement data, ImportContentSession importContentSession)
|
||||
: base(contentItem) {
|
||||
Data = data;
|
||||
@@ -23,6 +22,11 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ChildEl(string elementName, string childElementName) {
|
||||
var element = Data.Element(elementName);
|
||||
return element == null ? null : element.El(childElementName);
|
||||
}
|
||||
|
||||
public void ImportAttribute(string elementName, string attributeName, Action<string> value) {
|
||||
ImportAttribute(elementName, attributeName, value, () => { });
|
||||
}
|
||||
@@ -42,9 +46,27 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
}
|
||||
}
|
||||
|
||||
public void ImportChildEl(string elementName, string childElementName, Action<string> value) {
|
||||
ImportAttribute(elementName, childElementName, value, () => { });
|
||||
}
|
||||
|
||||
public void ImportChildEl(string elementName, string childElementName, Action<string> value, Action empty) {
|
||||
var importedText = ChildEl(elementName, childElementName);
|
||||
if (importedText != null) {
|
||||
try {
|
||||
value(importedText);
|
||||
}
|
||||
catch {
|
||||
empty();
|
||||
}
|
||||
}
|
||||
else {
|
||||
empty();
|
||||
}
|
||||
}
|
||||
|
||||
public ContentItem GetItemFromSession(string id) {
|
||||
return Session.Get(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user