U4-10875 - Umbraco 7.7.8 - Grid preview not working for nested macros

Created by Robert Ghafoor 22 Jan 2018, 14:26:54 Updated by Robert Ghafoor 06 Mar 2018, 22:42:12

I got a StartPageContentType with a grid If i have a macro with a simple content picker to pick a content and use it like this: @Html.GetTypedGridHtml(Umbraco.TypedContent(theMacroContentPickerPropertyId), "Grid", "ContentChild")

It's preview renders fine, but if i now add a second macro in the content type (theMacroContentPickerPropertyId) i get this error message in the preview on the "Home" content: (see attached image) the type of macro do not matter.

I think it may be connected to this issue the only diffrence is im using it with a grid and no rte is involved at all ttp://issues.umbraco.org/issue/U4-8759 ?

1 Attachments

Comments

Robert Ghafoor 06 Mar 2018, 22:42:12

I played around a bit with the base.cshtml file that is responsible for rendering a grid editor, i added this code

if (editor.EndsWith("macro"))
    {
        UmbracoContext.EnsureContext(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current, new Umbraco.Web.Security.WebSecurity(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current), Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings(), Umbraco.Web.Routing.UrlProviderResolver.Current.Providers, false);
        if (UmbracoContext.Current.PublishedContentRequest == null)
        {
            var t = UmbracoContext.Current.ContentCache.GetById(UmbracoContext.Current.PageId.Value).UrlWithDomain();
            UmbracoContext.Current.PublishedContentRequest = new PublishedContentRequest(new Uri(t), UmbracoContext.Current.RoutingContext, Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings().WebRouting, (Func<string, IEnumerable<string>>)(s => (IEnumerable<string>)Roles.Provider.GetRolesForUser(s)));
            UmbracoContext.Current.PublishedContentRequest.Prepare();
        }
    }

so the file looks like this:

@model dynamic
@using Umbraco.Web.Routing
@using Umbraco.Web.Templates

@functions {
    public static string EditorView(dynamic contentItem)
    {
        string view = contentItem.editor.render != null ? contentItem.editor.render.ToString() : contentItem.editor.view.ToString();
        view = view.ToLower().Replace(".html", ".cshtml");
        
        if (!view.Contains("/")) {
            view = "grid/editors/" + view;
        }

        return view;
    }
}
@try
{
    string editor = EditorView(Model);
    if (editor.EndsWith("macro"))
    {
        UmbracoContext.EnsureContext(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current, new Umbraco.Web.Security.WebSecurity(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current), Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings(), Umbraco.Web.Routing.UrlProviderResolver.Current.Providers, false);
        if (UmbracoContext.Current.PublishedContentRequest == null)
        {
            var t = UmbracoContext.Current.ContentCache.GetById(UmbracoContext.Current.PageId.Value).UrlWithDomain();
            UmbracoContext.Current.PublishedContentRequest = new PublishedContentRequest(new Uri(t), UmbracoContext.Current.RoutingContext, Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings().WebRouting, (Func<string, IEnumerable<string>>)(s => (IEnumerable<string>)Roles.Provider.GetRolesForUser(s)));
            UmbracoContext.Current.PublishedContentRequest.Prepare();
        }
    }
    <text>@Html.Partial(editor, (object)Model)</text>
}
catch (Exception ex) { 
<pre>@ex.ToString()</pre>
}

but if this really solves the problem then it should ether be added or fixed somehow ? anyway my button macro is rendering fine now that is nested in a macro, what i think the problem is the /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor can not handle nested macros it do however render fine in the frontend.


Priority: Normal

Type: Bug

State: Submitted

Assignee:

Difficulty:

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: