mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +08:00
Fix for issue 8631: field values are reset when imported (#8632)
* If there is nothing to import for MediaLibraryPickerField and ContentPickerField, the field doesn't need to be reset. * Checked the presence of the field inside the import context to avoid resetting the field value even if the field isn't imported. This applies to ContentPickerField, MediaLibraryPickerField and NumericField.
This commit is contained in:
committed by
GitHub
parent
8f73299406
commit
ba5873aece
@@ -89,8 +89,7 @@ namespace Orchard.ContentPicker.Drivers {
|
||||
|
||||
if (String.IsNullOrEmpty(model.SelectedIds)) {
|
||||
field.Ids = new int[0];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
field.Ids = model.SelectedIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
|
||||
}
|
||||
|
||||
@@ -102,14 +101,18 @@ namespace Orchard.ContentPicker.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ContentPart part, Fields.ContentPickerField field, ImportContentContext context) {
|
||||
var contentItemIds = context.Attribute(field.FieldDefinition.Name + "." + field.Name, "ContentItems");
|
||||
if (contentItemIds != null) {
|
||||
field.Ids = contentItemIds.Split(',')
|
||||
.Select(context.GetItemFromSession)
|
||||
.Select(contentItem => contentItem.Id).ToArray();
|
||||
}
|
||||
else {
|
||||
field.Ids = new int[0];
|
||||
// If nothing about the field is inside the context, field is not modified.
|
||||
// For this reason, check if the current element is inside the ImportContentContext.
|
||||
var element = context.Data.Element(field.FieldDefinition.Name + "." + field.Name);
|
||||
if (element != null) {
|
||||
var contentItemIds = context.Attribute(field.FieldDefinition.Name + "." + field.Name, "ContentItems");
|
||||
if (contentItemIds != null) {
|
||||
field.Ids = contentItemIds.Split(',')
|
||||
.Select(context.GetItemFromSession)
|
||||
.Select(contentItem => contentItem.Id).ToArray();
|
||||
} else {
|
||||
field.Ids = new int[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,13 @@ namespace Orchard.Fields.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ContentPart part, NumericField field, ImportContentContext context) {
|
||||
context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Value", v => field.Value = decimal.Parse(v, CultureInfo.InvariantCulture), () => field.Value = (decimal?)null);
|
||||
Action empty = (() => field.Value = (decimal?)null);
|
||||
var element = context.Data.Element(field.FieldDefinition.Name + "." + field.Name);
|
||||
// If element is not in the ImportContentContext, field must not be reset.
|
||||
if (element == null) {
|
||||
empty = () => { };
|
||||
}
|
||||
context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Value", v => field.Value = decimal.Parse(v, CultureInfo.InvariantCulture), empty);
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentPart part, NumericField field, ExportContentContext context) {
|
||||
|
||||
@@ -72,14 +72,20 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ContentPart part, Fields.MediaLibraryPickerField field, ImportContentContext context) {
|
||||
var contentItemIds = context.Attribute(field.FieldDefinition.Name + "." + field.Name, "ContentItems");
|
||||
if (contentItemIds != null) {
|
||||
field.Ids = contentItemIds.Split(',')
|
||||
.Select(context.GetItemFromSession)
|
||||
.Select(contentItem => contentItem.Id).ToArray();
|
||||
}
|
||||
else {
|
||||
field.Ids = new int[0];
|
||||
// If nothing about the field is inside the context, field is not modified.
|
||||
// For this reason, check if the current element is inside the ImportContentContext.
|
||||
var element = context.Data.Element(field.FieldDefinition.Name + "." + field.Name);
|
||||
if (element != null) {
|
||||
var contentItemIds = context.Attribute(field.FieldDefinition.Name + "." + field.Name, "ContentItems");
|
||||
if (contentItemIds != null) {
|
||||
if (!string.IsNullOrWhiteSpace(contentItemIds)) {
|
||||
field.Ids = contentItemIds.Split(',')
|
||||
.Select(context.GetItemFromSession)
|
||||
.Select(contentItem => contentItem.Id).ToArray();
|
||||
}
|
||||
} else {
|
||||
field.Ids = new int[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user