From c99798ac1b9e236cd56a4375f41ea7738eb30a0c Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 10 Jun 2020 14:33:32 +0100 Subject: [PATCH] Allows unpublished content to render a macro HTML in the RTE (cherry picked from commit 3680f22321c77b8732fbc4d94c26e399d19e6cdd) --- src/Umbraco.Web/Editors/MacroRenderingController.cs | 2 +- src/Umbraco.Web/IUmbracoComponentRenderer.cs | 13 +++++++++++++ src/Umbraco.Web/UmbracoComponentRenderer.cs | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Editors/MacroRenderingController.cs b/src/Umbraco.Web/Editors/MacroRenderingController.cs index 7aabff6822..33a58328b9 100644 --- a/src/Umbraco.Web/Editors/MacroRenderingController.cs +++ b/src/Umbraco.Web/Editors/MacroRenderingController.cs @@ -142,7 +142,7 @@ namespace Umbraco.Web.Editors //need to create a specific content result formatted as HTML since this controller has been configured //with only json formatters. result.Content = new StringContent( - _componentRenderer.RenderMacro(pageId, m.Alias, macroParams).ToString(), + _componentRenderer.RenderMacroForContent(publishedContent, m.Alias, macroParams).ToString(), Encoding.UTF8, "text/html"); diff --git a/src/Umbraco.Web/IUmbracoComponentRenderer.cs b/src/Umbraco.Web/IUmbracoComponentRenderer.cs index 4dc9036e6b..f05afe3f6b 100644 --- a/src/Umbraco.Web/IUmbracoComponentRenderer.cs +++ b/src/Umbraco.Web/IUmbracoComponentRenderer.cs @@ -42,5 +42,18 @@ namespace Umbraco.Web /// The parameters. /// IHtmlString RenderMacro(int contentId, string alias, IDictionary parameters); + + /// + /// Renders the macro with the specified alias, passing in the specified parameters. + /// + /// An IPublishedContent to use for the context for the macro rendering + /// The alias. + /// The parameters. + /// A raw HTML string of the macro output + /// + /// Currently only used when the node is unpublished and unable to get the contentId item from the + /// content cache as its unpublished. This deals with taking in a preview/draft version of the content node + /// + IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters); } } diff --git a/src/Umbraco.Web/UmbracoComponentRenderer.cs b/src/Umbraco.Web/UmbracoComponentRenderer.cs index 0373c73724..aa4cbefe7b 100644 --- a/src/Umbraco.Web/UmbracoComponentRenderer.cs +++ b/src/Umbraco.Web/UmbracoComponentRenderer.cs @@ -102,6 +102,15 @@ namespace Umbraco.Web return RenderMacro(content, alias, parameters); } + + public IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters) + { + if(content == null) + throw new InvalidOperationException("Cannot render a macro, IPublishedContent is null"); + + return RenderMacro(content, alias, parameters); + } + /// /// Renders the macro with the specified alias, passing in the specified parameters. ///