From 6c559e68614a40a50412e13bdd1a2b817f314918 Mon Sep 17 00:00:00 2001 From: DavidHayden Date: Mon, 24 Sep 2012 14:23:02 -0700 Subject: [PATCH] #18978: Implementing CustomForms import/export Work Item: 18978 --HG-- branch : 1.x --- .../Drivers/CustomFormPartDriver.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Drivers/CustomFormPartDriver.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Drivers/CustomFormPartDriver.cs index d059c8fc0..85a163fde 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Drivers/CustomFormPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Drivers/CustomFormPartDriver.cs @@ -6,6 +6,8 @@ using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.MetaData; using Orchard.CustomForms.Models; using Orchard.CustomForms.ViewModels; +using Orchard.ContentManagement.Handlers; +using System; namespace Orchard.CustomForms.Drivers { public class CustomFormPartDriver : ContentPartDriver { @@ -56,5 +58,29 @@ namespace Orchard.CustomForms.Drivers { updater.TryUpdateModel(viewModel, Prefix, null, null); return Editor(part, shapeHelper); } + + protected override void Importing(CustomFormPart part, ImportContentContext context) { + IfNotNull(context.Attribute(part.PartDefinition.Name, "ContentType"), x => part.Record.ContentType = x); + IfNotNull(context.Attribute(part.PartDefinition.Name, "SaveContentItem"), x => part.Record.SaveContentItem = Boolean.Parse(x)); + IfNotNull(context.Attribute(part.PartDefinition.Name, "CustomMessage"), x => part.Record.CustomMessage = Boolean.Parse(x)); + IfNotNull(context.Attribute(part.PartDefinition.Name, "Message"), x => part.Record.Message = x); + IfNotNull(context.Attribute(part.PartDefinition.Name, "Redirect"), x => part.Record.Redirect = Boolean.Parse(x)); + IfNotNull(context.Attribute(part.PartDefinition.Name, "RedirectUrl"), x => part.Record.RedirectUrl = x); + } + + private static void IfNotNull(T value, Action then) { + if (value != null) { + then(value); + } + } + + protected override void Exporting(CustomFormPart part, ExportContentContext context) { + context.Element(part.PartDefinition.Name).SetAttributeValue("ContentType", part.Record.ContentType); + context.Element(part.PartDefinition.Name).SetAttributeValue("SaveContentItem", part.Record.SaveContentItem); + context.Element(part.PartDefinition.Name).SetAttributeValue("CustomMessage", part.Record.CustomMessage); + context.Element(part.PartDefinition.Name).SetAttributeValue("Message", part.Record.Message); + context.Element(part.PartDefinition.Name).SetAttributeValue("Redirect", part.Record.Redirect); + context.Element(part.PartDefinition.Name).SetAttributeValue("RedirectUrl", part.Record.RedirectUrl); + } } } \ No newline at end of file