skttl
02/04/2025, 8:51 AMcs
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.DynamicRoot.QuerySteps;
using Umbraco.Cms.Core.Extensions;
using Umbraco.Cms.Core.Services;
namespace Website.Core.DynamicRoot;
public class GlobalDataNodeDynamicRootQueryStep : IDynamicRootQueryStep
{
private readonly IContentService _contentService;
public GlobalDataNodeDynamicRootQueryStep(IContentService contentService)
{
_contentService = contentService;
}
protected virtual string SupportedDirectionAlias { get; set; } = "GlobalDataNode";
public async Task<Attempt<ICollection<Guid>>> ExecuteAsync(ICollection<Guid> origins, DynamicRootQueryStep filter)
{
await Task.Run(() => { });
if (filter.Alias != SupportedDirectionAlias)
{
return Attempt<ICollection<Guid>>.Fail();
}
if (origins.Count < 1)
{
return Attempt<ICollection<Guid>>.Succeed(Array.Empty<Guid>());
}
var globalDataNode = _contentService.GetRootContent().FirstOrDefault(x => x.ContentType.Alias == ContentModels.GlobalDataNode.ModelTypeAlias);
if (globalDataNode == null)
{
return Attempt<ICollection<Guid>>.Succeed(Array.Empty<Guid>());
}
return Attempt<ICollection<Guid>>.Succeed(globalDataNode.Key.ToSingleItemCollection());
}
}
Luuk Peters (ProudNerds)
02/04/2025, 10:10 AMD_Inventor
02/04/2025, 4:52 PMIContentService
and fetch content at root and return the first result that has the content type alias that I'm looking for.
I would've preferred to add it as a custom query root, but for some reason they won't let us extend those (at least not when I checked, which is already a while ago)skttl
02/05/2025, 9:53 AMEpsilon Indi
02/07/2025, 9:53 AM