diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplay.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplay.cs index dcb292bb1ac..56d8e52fbcd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplay.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Drivers/FlowPartDisplay.cs @@ -63,19 +63,26 @@ public override async Task UpdateAsync(FlowPart part, UpdatePart await context.Updater.TryUpdateModelAsync(model, Prefix); - part.Widgets.Clear(); + var contentItems = new List(); for (var i = 0; i < model.Prefixes.Length; i++) { var contentItem = await _contentManager.NewAsync(model.ContentTypes[i]); + var existing = part.Widgets.FirstOrDefault(x => String.Equals(x.ContentItemId, model.Prefixes[i], StringComparison.OrdinalIgnoreCase)); + if (existing != null) + { + contentItem.ContentItemId = model.Prefixes[i]; + } contentItem.Weld(new FlowMetadata()); var widgetModel = await contentItemDisplayManager.UpdateEditorAsync(contentItem, context.Updater, context.IsNew, htmlFieldPrefix: model.Prefixes[i]); - part.Widgets.Add(contentItem); + contentItems.Add(contentItem); } + part.Widgets = contentItems; + return Edit(part, context); } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Models/FlowPart.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Models/FlowPart.cs index d795b95548f..d828fd26e50 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Models/FlowPart.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Models/FlowPart.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.ModelBinding; using OrchardCore.ContentManagement; @@ -7,6 +7,6 @@ namespace OrchardCore.Flows.Models public class FlowPart : ContentPart { [BindNever] - public List Widgets { get; } = new List(); + public List Widgets { get; set; } = new List(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Views/FlowPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Flows/Views/FlowPart.Edit.cshtml index 80c7823d5c7..504aad0c60d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Views/FlowPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Views/FlowPart.Edit.cshtml @@ -43,6 +43,7 @@ CanDelete: true, //Input hidden //Prefixes + PrefixValue: widget.ContentItemId, HtmlFieldPrefix: htmlFieldPrefix, PrefixesId: Html.IdFor(x => x.Prefixes), PrefixesName: Html.NameFor(x => x.Prefixes), diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplay.cs b/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplay.cs index a175fe21b05..561f94b006d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplay.cs +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Drivers/WidgetsListPartDisplay.cs @@ -94,7 +94,7 @@ public override async Task UpdateAsync(WidgetsListPart part, Upd await context.Updater.TryUpdateModelAsync(model, Prefix); - part.Widgets.Clear(); + var zonedContentItems = new Dictionary>(); // Remove any content or the zones would be merged and not be cleared part.Content.Widgets.RemoveAll(); @@ -106,19 +106,29 @@ public override async Task UpdateAsync(WidgetsListPart part, Upd var prefix = model.Prefixes[i]; var contentItem = await _contentManager.NewAsync(contentType); + if (part.Widgets.ContainsKey(zone)) + { + var existing = part.Widgets[zone].FirstOrDefault(x => String.Equals(x.ContentItemId, model.Prefixes[i], StringComparison.OrdinalIgnoreCase)); + if (existing != null) + { + contentItem.ContentItemId = model.Prefixes[i]; + } + } contentItem.Weld(new WidgetMetadata()); var widgetModel = await contentItemDisplayManager.UpdateEditorAsync(contentItem, context.Updater, context.IsNew, htmlFieldPrefix: prefix); - if (!part.Widgets.ContainsKey(zone)) + if (!zonedContentItems.ContainsKey(zone)) { - part.Widgets.Add(zone, new List()); + zonedContentItems.Add(zone, new List()); } - part.Widgets[zone].Add(contentItem); + zonedContentItems[zone].Add(contentItem); } + part.Widgets = zonedContentItems; + return Edit(part, context); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Models/WidgetsListPart.cs b/src/OrchardCore.Modules/OrchardCore.Widgets/Models/WidgetsListPart.cs index 231bd7dcc2b..187ddda753e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Models/WidgetsListPart.cs +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Models/WidgetsListPart.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using OrchardCore.ContentManagement; namespace OrchardCore.Widgets.Models @@ -6,6 +6,6 @@ namespace OrchardCore.Widgets.Models // A content item with this part can have widget instances. public class WidgetsListPart : ContentPart { - public Dictionary> Widgets { get; } = new Dictionary>(); + public Dictionary> Widgets { get; set; } = new Dictionary>(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml index cbcd95abf51..7cea2029564 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Views/WidgetsListPart.Edit.cshtml @@ -54,6 +54,7 @@ CanDelete: true, //Input hidden //Prefixes + PrefixValue: widget.ContentItemId, HtmlFieldPrefix: htmlFieldPrefix, PrefixesId: Html.IdFor(x => x.Prefixes), PrefixesName: Html.NameFor(x => x.Prefixes),