diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js
index e4201c6d3e..c8dc62fc6c 100644
--- a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js
+++ b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js
@@ -51,7 +51,7 @@ function macroResource($q, $http, umbRequestHelper) {
$http.post(
umbRequestHelper.getApiUrl(
"macroApiBaseUrl",
- "GetMacroResultAsHtmlForEditor",
+ "GetMacroResultAsHtmlForEditorUsingHttpPost",
query), JSON.stringify(macroParamDictionary)),
'Failed to retrieve macro result for macro with alias ' + macroAlias);
}
diff --git a/src/Umbraco.Web/Editors/MacroController.cs b/src/Umbraco.Web/Editors/MacroController.cs
index e14971db36..fed4fe6805 100644
--- a/src/Umbraco.Web/Editors/MacroController.cs
+++ b/src/Umbraco.Web/Editors/MacroController.cs
@@ -49,9 +49,8 @@ namespace Umbraco.Web.Editors
///
///
///
- [HttpPost]
[HttpGet]
- public HttpResponseMessage GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromBody]IDictionary macroParams)
+ public HttpResponseMessage GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromUri] IDictionary macroParams)
{
// note - here we should be using the cache, provided that the preview content is in the cache...
@@ -83,7 +82,66 @@ namespace Umbraco.Web.Editors
//the 'easiest' way might be to create an IPublishedContent manually and populate the legacy 'page' object with that
//and then set the legacy parameters.
- var legacyPage = new global::umbraco.page(doc);
+ var legacyPage = new global::umbraco.page(doc);
+ UmbracoContext.HttpContext.Items["pageID"] = doc.Id;
+ UmbracoContext.HttpContext.Items["pageElements"] = legacyPage.Elements;
+ UmbracoContext.HttpContext.Items[global::Umbraco.Core.Constants.Conventions.Url.AltTemplate] = null;
+
+ var renderer = new UmbracoComponentRenderer(UmbracoContext);
+
+ var result = Request.CreateResponse();
+ //need to create a specific content result formatted as html since this controller has been configured
+ //with only json formatters.
+ result.Content = new StringContent(
+ renderer.RenderMacro(macro, macroParams, legacyPage).ToString(),
+ Encoding.UTF8,
+ "text/html");
+ return result;
+ }
+
+ ///
+ /// Gets a rendered macro as html for rendering in the rich text editor.
+ /// Using HTTP POST instead of GET allows for more parameters to be passed as it's not dependant on URL-length limitations like GET.
+ /// The method using GET is kept to maintain backwards compatibility
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost]
+ public HttpResponseMessage GetMacroResultAsHtmlForEditorUsingHttpPost(string macroAlias, int pageId, [FromBody]IDictionary macroParams)
+ {
+ // note - here we should be using the cache, provided that the preview content is in the cache...
+
+ var doc = Services.ContentService.GetById(pageId);
+ if (doc == null)
+ {
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+
+ //need to get a legacy macro object - eventually we'll have a new format but nto yet
+ var macro = new macro(macroAlias);
+ if (macro == null)
+ {
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+
+ //if it isn't supposed to be rendered in the editor then return an empty string
+ if (macro.DontRenderInEditor)
+ {
+ var response = Request.CreateResponse();
+ //need to create a specific content result formatted as html since this controller has been configured
+ //with only json formatters.
+ response.Content = new StringContent(string.Empty, Encoding.UTF8, "text/html");
+
+ return response;
+ }
+
+ //because macro's are filled with insane legacy bits and pieces we need all sorts of wierdness to make them render.
+ //the 'easiest' way might be to create an IPublishedContent manually and populate the legacy 'page' object with that
+ //and then set the legacy parameters.
+
+ var legacyPage = new global::umbraco.page(doc);
UmbracoContext.HttpContext.Items["pageID"] = doc.Id;
UmbracoContext.HttpContext.Items["pageElements"] = legacyPage.Elements;
UmbracoContext.HttpContext.Items[global::Umbraco.Core.Constants.Conventions.Url.AltTemplate] = null;