Fixes issue with rendering macro content when the page doesn't exist
This commit is contained in:
@@ -108,6 +108,8 @@ namespace Umbraco.Web.Editors
|
||||
if (string.IsNullOrEmpty(query))
|
||||
return Enumerable.Empty<EntityBasic>();
|
||||
|
||||
//TODO: This uses the internal UmbracoTreeSearcher, this instead should delgate to the ISearchableTree implementation for the type
|
||||
|
||||
return ExamineSearch(query, type, searchFrom);
|
||||
}
|
||||
|
||||
@@ -451,6 +453,9 @@ namespace Umbraco.Web.Editors
|
||||
//the EntityService cannot search members of a certain type, this is currently not supported and would require
|
||||
//quite a bit of plumbing to do in the Services/Repository, we'll revert to a paged search
|
||||
|
||||
//TODO: We should really fix this in the EntityService but if we don't we should allow the ISearchableTree for the members controller
|
||||
// to be used for this search instead of the built in/internal searcher
|
||||
|
||||
var searchResult = _treeSearcher.ExamineSearch(filter ?? "", type, pageSize, pageNumber - 1, out long total, id);
|
||||
|
||||
return new PagedResult<EntityBasic>(total, pageNumber, pageSize)
|
||||
|
||||
@@ -102,18 +102,13 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
private HttpResponseMessage GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary<string, object> macroParams)
|
||||
{
|
||||
// note - here we should be using the cache, provided that the preview content is in the cache...
|
||||
|
||||
var doc = _contentService.GetById(pageId);
|
||||
if (doc == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
|
||||
var m = _macroService.GetByAlias(macroAlias);
|
||||
if (m == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
|
||||
//if it isn't supposed to be rendered in the editor then return an empty string
|
||||
if (!m.UseInEditor)
|
||||
//currently we cannot render a macro if the page doesn't yet exist
|
||||
if (pageId == -1 || !m.UseInEditor)
|
||||
{
|
||||
var response = Request.CreateResponse();
|
||||
//need to create a specific content result formatted as HTML since this controller has been configured
|
||||
@@ -130,7 +125,7 @@ namespace Umbraco.Web.Editors
|
||||
// When rendering the macro in the backoffice the default setting would be to use the Culture of the logged in user.
|
||||
// Since a Macro might contain thing thats related to the culture of the "IPublishedContent" (ie Dictionary keys) we want
|
||||
// to set the current culture to the culture related to the content item. This is hacky but it works.
|
||||
var publishedContent = UmbracoContext.ContentCache.GetById(doc.Id);
|
||||
var publishedContent = UmbracoContext.ContentCache.GetById(pageId);
|
||||
var culture = publishedContent?.GetCulture();
|
||||
_variationContextAccessor.VariationContext = new VariationContext(); //must have an active variation context!
|
||||
if (culture != null)
|
||||
@@ -143,7 +138,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(doc.Id, m.Alias, macroParams).ToString(),
|
||||
_componentRenderer.RenderMacro(pageId, m.Alias, macroParams).ToString(),
|
||||
Encoding.UTF8,
|
||||
"text/html");
|
||||
return result;
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace Umbraco.Web.Models
|
||||
MacroId = macroId;
|
||||
}
|
||||
|
||||
public IPublishedContent Content { get; private set; }
|
||||
public string MacroName { get; private set; }
|
||||
public string MacroAlias { get; private set; }
|
||||
public int MacroId { get; private set; }
|
||||
public IDictionary<string, object> MacroParameters { get; private set; }
|
||||
public IPublishedContent Content { get; }
|
||||
public string MacroName { get; }
|
||||
public string MacroAlias { get; }
|
||||
public int MacroId { get; }
|
||||
public IDictionary<string, object> MacroParameters { get; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user