#21151 : Import with LayoutPart Fails if not in XML.

Work Item: 21151
This commit is contained in:
Jay Harris
2015-02-14 16:19:14 +00:00
committed by agriffard
parent 4ac29a3937
commit dac17198f6
2 changed files with 32 additions and 6 deletions

View File

@@ -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));
}

View File

@@ -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);
}
}
}