From 5a47acceda45e4431ef8268a71ced3738b79d96c Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 17 Aug 2021 14:36:19 +0200 Subject: [PATCH] Raise SendingContentModel event for each element type in blocklist (#10869) Co-authored-by: Nikolaj --- .../OutgoingEditorModelEventAttribute.cs | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs b/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs index e2a6f155d0..25585ca0cb 100644 --- a/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs @@ -1,10 +1,8 @@ -using System; +using System.Collections; using System.Net.Http; using System.Web.Http.Filters; -using Umbraco.Core; using Umbraco.Web.Composing; using Umbraco.Web.Editors; -using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.WebApi.Filters { @@ -23,18 +21,37 @@ namespace Umbraco.Web.WebApi.Filters if (actionExecutedContext.Response.Content is ObjectContent objectContent) { var model = objectContent.Value; - if (model != null) { - var args = new EditorModelEventArgs( - model, - Current.UmbracoContext); - EditorModelEventManager.EmitEvent(actionExecutedContext, args); - objectContent.Value = args.Model; + if (model is IDictionary modelDict) + { + foreach (var entity in modelDict) + { + if (entity is DictionaryEntry entry) + { + var args = CreateArgs(entry.Value); + EditorModelEventManager.EmitEvent(actionExecutedContext, args); + entry.Value = args.Model; + } + } + } + else + { + var args = CreateArgs(model); + EditorModelEventManager.EmitEvent(actionExecutedContext, args); + objectContent.Value = args.Model; + } } } base.OnActionExecuted(actionExecutedContext); } + + private EditorModelEventArgs CreateArgs(object model) + { + return new EditorModelEventArgs( + model, + Current.UmbracoContext); + } } }