From 7d458a8b67d1961c04460e09f8f9c52ca263bba9 Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:01:04 -0600 Subject: [PATCH 01/11] DisplayAsync to return actual pre-rendered IHtmlContent instead of PositionWrapper. Fixes #15235 Fixes #15211 --- .../Implementation/DefaultHtmlDisplay.cs | 14 +++++++++++++- .../Implementation/DisplayHelper.cs | 15 ++++++++++++++- .../PositionWrapper.cs | 8 ++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs index fab1d676f32..77f65cffa82 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs @@ -50,7 +50,19 @@ public async Task ExecuteAsync(DisplayContext context) // Check if the shape is pre-rendered. if (shape is IHtmlContent htmlContent) { - return htmlContent; + if (htmlContent is PositionWrapper wrapper) + { + while (wrapper.Value is PositionWrapper) + { + wrapper = (PositionWrapper)wrapper.Value; + } + + return wrapper.Value; + } + else + { + return htmlContent; + } } var shapeMetadata = shape.Metadata; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs index 99b757f4e5d..c8ad2757f65 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; +using Microsoft.CodeAnalysis.CSharp.Syntax; namespace OrchardCore.DisplayManagement.Implementation { @@ -75,7 +76,19 @@ public Task ShapeExecuteAsync(IShape shape) // Check if the shape is pre-rendered. if (shape is IHtmlContent htmlContent) { - return Task.FromResult(htmlContent); + if (shape is PositionWrapper wrapper) + { + while(wrapper.Value is PositionWrapper) + { + wrapper = (PositionWrapper) wrapper.Value; + } + + return Task.FromResult(wrapper.Value); + } + else + { + return Task.FromResult(htmlContent); + } } var context = new DisplayContext diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index 94ee0248dfa..c69f881f1b3 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -41,6 +41,14 @@ public PositionWrapper(string value, string position) Position = position; } + internal IHtmlContent Value + { + get + { + return _value; + } + } + public void WriteTo(TextWriter writer, HtmlEncoder encoder) { _value.WriteTo(writer, encoder); From eb7a1f095d829ea644dc5eb30aeabbe7d2e744fb Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:23:37 -0600 Subject: [PATCH 02/11] react to feedback --- .../Implementation/DefaultHtmlDisplay.cs | 6 ++---- .../Implementation/DisplayHelper.cs | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs index 77f65cffa82..2b8bae33ee0 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs @@ -59,10 +59,8 @@ public async Task ExecuteAsync(DisplayContext context) return wrapper.Value; } - else - { - return htmlContent; - } + + return htmlContent; } var shapeMetadata = shape.Metadata; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs index c8ad2757f65..e3cd71a68e8 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs @@ -78,17 +78,15 @@ public Task ShapeExecuteAsync(IShape shape) { if (shape is PositionWrapper wrapper) { - while(wrapper.Value is PositionWrapper) + while (wrapper.Value is PositionWrapper) { - wrapper = (PositionWrapper) wrapper.Value; + wrapper = (PositionWrapper)wrapper.Value; } - + return Task.FromResult(wrapper.Value); } - else - { - return Task.FromResult(htmlContent); - } + + return Task.FromResult(htmlContent); } var context = new DisplayContext From 6bfff18e5a9af9b39c2e753404e5fa314f88eccf Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:29:00 -0600 Subject: [PATCH 03/11] update property --- .../OrchardCore.DisplayManagement/PositionWrapper.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index c69f881f1b3..755edd56aad 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -11,6 +11,8 @@ namespace OrchardCore.DisplayManagement public class PositionWrapper : IHtmlContent, IPositioned, IShape { private readonly IHtmlContent _value; + internal IHtmlContent Value => _value; + public string Position { get; set; } public ShapeMetadata Metadata { get; set; } = new ShapeMetadata(); @@ -41,14 +43,6 @@ public PositionWrapper(string value, string position) Position = position; } - internal IHtmlContent Value - { - get - { - return _value; - } - } - public void WriteTo(TextWriter writer, HtmlEncoder encoder) { _value.WriteTo(writer, encoder); From 01f86e9a924c078171e3cd7313c3194a65c2fa33 Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 3 Feb 2024 13:05:30 -0600 Subject: [PATCH 04/11] remove cast --- .../Implementation/DefaultHtmlDisplay.cs | 4 ++-- .../Implementation/DisplayHelper.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs index 2b8bae33ee0..0ea54f9305b 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs @@ -52,9 +52,9 @@ public async Task ExecuteAsync(DisplayContext context) { if (htmlContent is PositionWrapper wrapper) { - while (wrapper.Value is PositionWrapper) + while (wrapper.Value is PositionWrapper wrapperValue) { - wrapper = (PositionWrapper)wrapper.Value; + wrapper = wrapperValue; } return wrapper.Value; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs index e3cd71a68e8..39f16cdd49a 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs @@ -78,9 +78,9 @@ public Task ShapeExecuteAsync(IShape shape) { if (shape is PositionWrapper wrapper) { - while (wrapper.Value is PositionWrapper) + while (wrapper.Value is PositionWrapper wrapperValue) { - wrapper = (PositionWrapper)wrapper.Value; + wrapper = wrapperValue; } return Task.FromResult(wrapper.Value); From 72b54e8b5e0817caab8b491042109a2c6b5e5007 Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:56:07 -0600 Subject: [PATCH 05/11] Update DisplayHelper.cs --- .../Implementation/DisplayHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs index 39f16cdd49a..82a3468189f 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; -using Microsoft.CodeAnalysis.CSharp.Syntax; namespace OrchardCore.DisplayManagement.Implementation { From 6fb8f0ef956cd8992487e1ef47f2b26af45ce47f Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:49:31 -0600 Subject: [PATCH 06/11] Added static methods TryWrap/Unwrap in PositionWrapper. PositionWrapper is now sealed and have private constructor. --- .../Implementation/DefaultHtmlDisplay.cs | 16 ++++------ .../Implementation/DisplayHelper.cs | 16 ++++------ .../PositionWrapper.cs | 30 +++++++++++++++---- .../Shapes/Shape.cs | 8 ++--- .../Theming/ThemeLayout.cs | 4 +-- .../Views/ShapeViewModel.cs | 8 ++--- 6 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs index 0ea54f9305b..85f3e19c9f6 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultHtmlDisplay.cs @@ -47,19 +47,15 @@ public async Task ExecuteAsync(DisplayContext context) return HtmlString.Empty; } + // Check if the shape is Position Wrapper + if(shape is PositionWrapper wrapper) + { + return PositionWrapper.UnWrap(wrapper); + } + // Check if the shape is pre-rendered. if (shape is IHtmlContent htmlContent) { - if (htmlContent is PositionWrapper wrapper) - { - while (wrapper.Value is PositionWrapper wrapperValue) - { - wrapper = wrapperValue; - } - - return wrapper.Value; - } - return htmlContent; } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs index 82a3468189f..d293c15eb9b 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DisplayHelper.cs @@ -72,19 +72,15 @@ public Task ShapeExecuteAsync(IShape shape) return Task.FromResult(HtmlString.Empty); } + // Check if the shape is wrapper, return underlying IHtmlContent + if( shape is PositionWrapper wrapper) + { + return Task.FromResult(PositionWrapper.UnWrap(wrapper)); + } + // Check if the shape is pre-rendered. if (shape is IHtmlContent htmlContent) { - if (shape is PositionWrapper wrapper) - { - while (wrapper.Value is PositionWrapper wrapperValue) - { - wrapper = wrapperValue; - } - - return Task.FromResult(wrapper.Value); - } - return Task.FromResult(htmlContent); } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index 755edd56aad..d215ffe99b5 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Text.Encodings.Web; @@ -8,11 +9,9 @@ namespace OrchardCore.DisplayManagement { - public class PositionWrapper : IHtmlContent, IPositioned, IShape + public sealed class PositionWrapper : IHtmlContent, IPositioned, IShape { private readonly IHtmlContent _value; - internal IHtmlContent Value => _value; - public string Position { get; set; } public ShapeMetadata Metadata { get; set; } = new ShapeMetadata(); @@ -31,13 +30,13 @@ public class PositionWrapper : IHtmlContent, IPositioned, IShape public IReadOnlyList Items => throw new System.NotImplementedException(); - public PositionWrapper(IHtmlContent value, string position) + private PositionWrapper(IHtmlContent value, string position) { _value = value; Position = position; } - public PositionWrapper(string value, string position) + private PositionWrapper(string value, string position) { _value = new HtmlContentString(value); Position = position; @@ -52,5 +51,26 @@ public ValueTask AddAsync(object item, string position) { throw new System.NotImplementedException(); } + + public static PositionWrapper TryWrap(object value, string position) + { + if (value is PositionWrapper wrapper) + { + // Update the new Position + wrapper.Position = position; + return wrapper; + } + else if (value is IHtmlContent content) + return new PositionWrapper(content, position); + else if (value is string stringContent) + return new PositionWrapper(stringContent, position); + else + throw new System.NotSupportedException($"Type of {nameof(value)} must be either {nameof(String)}, {nameof(IHtmlContent)} or {nameof(PositionWrapper)}."); + } + + public static IHtmlContent UnWrap(PositionWrapper wrapper) + { + return wrapper._value; + } } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs index ae7f47ea11d..e16f626a1a3 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs @@ -65,13 +65,13 @@ public virtual ValueTask AddAsync(object item, string position) _items ??= []; - if (item is IHtmlContent) + if (item is IHtmlContent htmlContent) { - _items.Add(new PositionWrapper((IHtmlContent)item, position)); + _items.Add(PositionWrapper.TryWrap(htmlContent, position)); } - else if (item is string) + else if (item is string stringContent) { - _items.Add(new PositionWrapper((string)item, position)); + _items.Add(PositionWrapper.TryWrap(stringContent, position)); } else { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs index a57a39285b4..f21b7feaed5 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs @@ -27,7 +27,7 @@ public override async Task ExecuteAsync() await ThemeLayout.Zones["Content"].AddAsync(body); // Pre-render all shapes and replace the zone content with it. - ThemeLayout.Zones["Content"] = new PositionWrapper(await DisplayAsync(ThemeLayout.Zones["Content"]), ""); + ThemeLayout.Zones["Content"] = PositionWrapper.TryWrap(await DisplayAsync(ThemeLayout.Zones["Content"]), ""); // Render each layout zone. foreach (var zone in ThemeLayout.Properties.ToArray()) @@ -46,7 +46,7 @@ public override async Task ExecuteAsync() continue; } - ThemeLayout.Zones[zone.Key] = new PositionWrapper(await DisplayAsync(shape), ""); + ThemeLayout.Zones[zone.Key] = PositionWrapper.TryWrap(await DisplayAsync(shape), ""); } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs index 109699a581d..1cba0ba5d36 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs @@ -81,13 +81,13 @@ public ValueTask AddAsync(object item, string position) _sorted = false; _items ??= []; - if (item is IHtmlContent) + if (item is IHtmlContent htmlContent) { - _items.Add(new PositionWrapper((IHtmlContent)item, position)); + _items.Add(PositionWrapper.TryWrap(htmlContent, position)); } - else if (item is string) + else if (item is string stringContent) { - _items.Add(new PositionWrapper((string)item, position)); + _items.Add(PositionWrapper.TryWrap(stringContent, position)); } else { From 47ddfa11a59760110b4ea15f6ddab250413bc44d Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Sat, 10 Feb 2024 16:09:35 -0600 Subject: [PATCH 07/11] formatting --- .../OrchardCore.DisplayManagement/PositionWrapper.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index d215ffe99b5..644541fca01 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -69,8 +69,6 @@ public static PositionWrapper TryWrap(object value, string position) } public static IHtmlContent UnWrap(PositionWrapper wrapper) - { - return wrapper._value; - } + => wrapper._value; } } From 4f14544c7c309c35a269a251ce163ff5adc3ba27 Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:08:54 -0600 Subject: [PATCH 08/11] react to review comments --- .../PositionWrapper.cs | 5 ++-- .../Shapes/Shape.cs | 24 +++---------------- .../Views/ShapeViewModel.cs | 24 +++---------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index 644541fca01..e1718b8870a 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -57,7 +57,8 @@ public static PositionWrapper TryWrap(object value, string position) if (value is PositionWrapper wrapper) { // Update the new Position - wrapper.Position = position; + if (position != null) + wrapper.Position = position; return wrapper; } else if (value is IHtmlContent content) @@ -65,7 +66,7 @@ public static PositionWrapper TryWrap(object value, string position) else if (value is string stringContent) return new PositionWrapper(stringContent, position); else - throw new System.NotSupportedException($"Type of {nameof(value)} must be either {nameof(String)}, {nameof(IHtmlContent)} or {nameof(PositionWrapper)}."); + return null; } public static IHtmlContent UnWrap(PositionWrapper wrapper) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs index e16f626a1a3..3650eb46939 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs @@ -65,27 +65,9 @@ public virtual ValueTask AddAsync(object item, string position) _items ??= []; - if (item is IHtmlContent htmlContent) - { - _items.Add(PositionWrapper.TryWrap(htmlContent, position)); - } - else if (item is string stringContent) - { - _items.Add(PositionWrapper.TryWrap(stringContent, position)); - } - else - { - var shape = item as IPositioned; - if (shape != null) - { - if (position != null) - { - shape.Position = position; - } - - _items.Add(shape); - } - } + var wrapped = PositionWrapper.TryWrap(item, position); + if (wrapped is not null) + _items.Add(wrapped); return new ValueTask(this); } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs index 1cba0ba5d36..2ed5829d35d 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Views/ShapeViewModel.cs @@ -81,27 +81,9 @@ public ValueTask AddAsync(object item, string position) _sorted = false; _items ??= []; - if (item is IHtmlContent htmlContent) - { - _items.Add(PositionWrapper.TryWrap(htmlContent, position)); - } - else if (item is string stringContent) - { - _items.Add(PositionWrapper.TryWrap(stringContent, position)); - } - else - { - if (item is IPositioned shape) - { - if (position != null) - { - shape.Position = position; - } - - _items.Add(shape); - } - } - + var wrapped = PositionWrapper.TryWrap(item, position); + if (wrapped is not null) + _items.Add(wrapped); return new ValueTask(this); } } From 0393d53f6b08f1252a16467ffd00d1a5f36a40b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 21 Feb 2024 12:14:42 -0800 Subject: [PATCH 09/11] Update PositionWrapper.cs --- .../OrchardCore.DisplayManagement/PositionWrapper.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index e1718b8870a..446750e3160 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -58,15 +58,23 @@ public static PositionWrapper TryWrap(object value, string position) { // Update the new Position if (position != null) + { wrapper.Position = position; + } return wrapper; } else if (value is IHtmlContent content) + { return new PositionWrapper(content, position); + } else if (value is string stringContent) + { return new PositionWrapper(stringContent, position); + } else + { return null; + } } public static IHtmlContent UnWrap(PositionWrapper wrapper) From e42fac8d9edf2bcec0674a1787aa567b24bd76f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 21 Feb 2024 12:15:14 -0800 Subject: [PATCH 10/11] Update Shape.cs --- src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs index 3650eb46939..662b9013ad6 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Shapes/Shape.cs @@ -67,7 +67,9 @@ public virtual ValueTask AddAsync(object item, string position) var wrapped = PositionWrapper.TryWrap(item, position); if (wrapped is not null) + { _items.Add(wrapped); + } return new ValueTask(this); } From b331411179ae05205c4148206e8d04b2958b8ac4 Mon Sep 17 00:00:00 2001 From: Niraj Soni <23270244+ns8482e@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:40:58 -0600 Subject: [PATCH 11/11] changed PositionWrapper to IPositioned --- .../OrchardCore.DisplayManagement/PositionWrapper.cs | 4 ++-- .../OrchardCore.DisplayManagement/Theming/ThemeLayout.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs index 446750e3160..b0d7841d1d3 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/PositionWrapper.cs @@ -52,9 +52,9 @@ public ValueTask AddAsync(object item, string position) throw new System.NotImplementedException(); } - public static PositionWrapper TryWrap(object value, string position) + public static IPositioned TryWrap(object value, string position) { - if (value is PositionWrapper wrapper) + if (value is IPositioned wrapper) { // Update the new Position if (position != null) diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs index f21b7feaed5..6c5d60ab014 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Theming/ThemeLayout.cs @@ -27,7 +27,7 @@ public override async Task ExecuteAsync() await ThemeLayout.Zones["Content"].AddAsync(body); // Pre-render all shapes and replace the zone content with it. - ThemeLayout.Zones["Content"] = PositionWrapper.TryWrap(await DisplayAsync(ThemeLayout.Zones["Content"]), ""); + ThemeLayout.Zones["Content"] = PositionWrapper.TryWrap(await DisplayAsync(ThemeLayout.Zones["Content"]), "") as IShape; // Render each layout zone. foreach (var zone in ThemeLayout.Properties.ToArray()) @@ -46,7 +46,7 @@ public override async Task ExecuteAsync() continue; } - ThemeLayout.Zones[zone.Key] = PositionWrapper.TryWrap(await DisplayAsync(shape), ""); + ThemeLayout.Zones[zone.Key] = PositionWrapper.TryWrap(await DisplayAsync(shape), "") as IShape; } }