mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Changed field drivers to not export empty elements.
This results in much cleaner recipes.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -85,6 +86,7 @@ namespace Orchard.Core.Common.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, TextField field, ExportContentContext context) {
|
||||
if (!String.IsNullOrEmpty(field.Value))
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Text", field.Value);
|
||||
}
|
||||
|
||||
|
@@ -61,6 +61,7 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, BooleanField field, ExportContentContext context) {
|
||||
if (field.Value.HasValue)
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", field.Value);
|
||||
}
|
||||
|
||||
|
@@ -167,7 +167,9 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, DateTimeField field, ExportContentContext context) {
|
||||
context.Element(GetPrefix(field, part)).SetAttributeValue("Value", XmlConvert.ToString(field.Storage.Get<DateTime>(null), XmlDateTimeSerializationMode.Utc));
|
||||
var value = field.Storage.Get<DateTime>(null);
|
||||
if (value != DateTime.MinValue)
|
||||
context.Element(GetPrefix(field, part)).SetAttributeValue("Value", XmlConvert.ToString(value, XmlDateTimeSerializationMode.Utc));
|
||||
}
|
||||
|
||||
protected override void Describe(DescribeMembersContext context) {
|
||||
|
@@ -4,6 +4,7 @@ using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Fields.Settings;
|
||||
using Orchard.Fields.Fields;
|
||||
using Orchard.Localization;
|
||||
using System;
|
||||
|
||||
namespace Orchard.Fields.Drivers {
|
||||
public class EnumerationFieldDriver : ContentFieldDriver<EnumerationField> {
|
||||
@@ -51,6 +52,7 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, EnumerationField field, ExportContentContext context) {
|
||||
if (!String.IsNullOrEmpty(field.Value))
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", field.Value);
|
||||
}
|
||||
|
||||
|
@@ -56,6 +56,7 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, InputField field, ExportContentContext context) {
|
||||
if (!String.IsNullOrEmpty(field.Value))
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", field.Value);
|
||||
}
|
||||
|
||||
|
@@ -62,10 +62,12 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, LinkField field, ExportContentContext context) {
|
||||
if (!String.IsNullOrEmpty(field.Text) && !String.IsNullOrEmpty(field.Value) && !String.IsNullOrEmpty(field.Target)) {
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Text", field.Text);
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Url", field.Value);
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Target", field.Target);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Describe(DescribeMembersContext context) {
|
||||
context
|
||||
|
@@ -104,7 +104,8 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, NumericField field, ExportContentContext context) {
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", !field.Value.HasValue ? String.Empty : field.Value.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (field.Value.HasValue)
|
||||
context.Element(field.FieldDefinition.Name + "." + field.Name).SetAttributeValue("Value", field.Value.Value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
protected override void Describe(DescribeMembersContext context) {
|
||||
|
@@ -108,9 +108,9 @@ namespace Orchard.Taxonomies.Drivers {
|
||||
var appliedTerms = _taxonomyService.GetTermsForContentItem(part.ContentItem.Id, field.Name);
|
||||
|
||||
// stores all content items associated to this field
|
||||
var termIdentities = appliedTerms.Select(x => Services.ContentManager.GetItemMetadata(x).Identity.ToString())
|
||||
.ToArray();
|
||||
var termIdentities = appliedTerms.Select(x => Services.ContentManager.GetItemMetadata(x).Identity.ToString()).ToArray();
|
||||
|
||||
if (termIdentities.Any())
|
||||
context.Element(XmlConvert.EncodeLocalName(field.FieldDefinition.Name + "." + field.Name)).SetAttributeValue("Terms", String.Join(",", termIdentities));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user