Added LayoutSaving call to context in WidgetElementHarvester to properly update the container of widgets. (#8534)

This commit is contained in:
Andrea Piovanelli
2022-02-09 10:20:30 +01:00
committed by GitHub
parent ea3c7d89b1
commit 88a79cb768

View File

@@ -47,11 +47,30 @@ namespace Orchard.Widgets.Layouts.Providers {
Importing = ImportElement,
StateBag = new Dictionary<string, object> {
{ "ContentTypeName", contentTypeDefinition.Name }
}
},
LayoutSaving = LayoutSaving
};
});
}
private void LayoutSaving(ElementSavingContext context) {
// I need to save the widget element container.
var element = (Widget)context.Element;
if (element == null) {
return;
}
var widgetId = element.WidgetId;
var widget = _contentManager.Value.Get(widgetId.Value, VersionOptions.Latest);
if (widget == null) {
return;
}
var commonPart = widget.As<ICommonPart>();
if (commonPart != null) {
commonPart.Container = context.Content;
}
}
private void Displaying(ElementDisplayingContext context) {
var contentTypeName = (string)context.Element.Descriptor.StateBag["ContentTypeName"];
var element = (Widget)context.Element;