Skip to content

Instantly share code, notes, and snippets.

@pbering
Created November 3, 2022 10:50
Show Gist options
  • Save pbering/36fcf14de2ca0835417269980b13cebe to your computer and use it in GitHub Desktop.
Save pbering/36fcf14de2ca0835417269980b13cebe to your computer and use it in GitHub Desktop.
FixSxaHeadlessNavigationContentResolver
using Newtonsoft.Json.Linq;
using Sitecore.LayoutService.Configuration;
using Sitecore.LayoutService.ItemRendering.ContentsResolvers;
using Sitecore.Mvc.Presentation;
using Sitecore.XA.JSS.Feature.Navigation.ContentsResolvers;
using System.Collections.Specialized;
namespace XmCloudSXAStarter.Patches
{
public class FixSxaHeadlessNavigationContentResolver : IRenderingContentsResolver
{
private readonly NavigationContentResolver _orginal;
public bool IncludeServerUrlInMediaUrls { get; set; }
public bool UseContextItem { get; set; }
public string ItemSelectorQuery { get; set; }
public NameValueCollection Parameters { get; set; }
public FixSxaHeadlessNavigationContentResolver()
{
_orginal = new NavigationContentResolver
{
IncludeServerUrlInMediaUrls = IncludeServerUrlInMediaUrls,
UseContextItem = UseContextItem,
ItemSelectorQuery = ItemSelectorQuery,
Parameters = Parameters
};
}
public object ResolveContents(Rendering rendering, IRenderingConfiguration renderingConfig)
{
var originalContents = _orginal.ResolveContents(rendering, renderingConfig);
var jObject = new JObject
{
new JProperty("Items", new JObject(new JProperty("value", originalContents)))
};
return jObject;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment