Split Get and Post
Split Get and Post into 2 separate methods to maintain backwards compability
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,8 @@ namespace Umbraco.Web.Editors
|
||||
///
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public HttpResponseMessage GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromBody]IDictionary<string, object> macroParams)
|
||||
public HttpResponseMessage GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromUri] IDictionary<string, object> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="macroAlias"></param>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="macroParams"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public HttpResponseMessage GetMacroResultAsHtmlForEditorUsingHttpPost(string macroAlias, int pageId, [FromBody]IDictionary<string, object> 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;
|
||||
|
||||
Reference in New Issue
Block a user