November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Ended up using an ApiModelProperty to store the pages that fallback. Something like this:
namespace X.X.X;
using System;
using System.Collections.Generic;
using System.Linq;
using EPiServer.ContentApi.Core.Serialization.Models;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.ServiceLocation;
using EPiServer.Web.Routing;
using Optimizely.ContentGraph.Cms.Core.ContentApiModelProperties.Internal;
using Optimizely.ContentGraph.Cms.NetCore.Extensions.Internal;
[ServiceConfiguration(typeof(IContentApiModelProperty), Lifecycle = ServiceInstanceScope.Singleton)]
public class FallbackLanguagesApiModelProperty(
ILanguageBranchRepository languageBranchRepository,
IUrlResolver urlResolver,
IContentLanguageSettingsHandler contentLanguageSettingsHandler) : IContentApiModelProperty
{
public object GetValue(ContentApiModel contentApiModel)
{
if(contentApiModel.ContentLink != null)
{
var enabledLanguages = languageBranchRepository.ListEnabled();
var pagesThatFallBackToCurrentPage = new List<string>();
var cRef = contentApiModel.ContentLink.ToContentReference();
foreach (var enabledLanguage in enabledLanguages)
{
var fallbackLanguages = contentLanguageSettingsHandler.GetFallbackLanguages(cRef, enabledLanguage.Culture.Name);
if (fallbackLanguages.Any() && fallbackLanguages.Contains(contentApiModel.Language.Name))
{
var lang = enabledLanguage.Culture.Name;
var url = urlResolver.GetUrl(cRef, lang);
pagesThatFallBackToCurrentPage.Add($"{lang}|{url}");
}
}
return pagesThatFallBackToCurrentPage;
}
else
{
return new List<string>();
}
}
public string Name => "PagesThatFallback";
}
And a rough query to return the right data:
query MyQuery {
SitePageData(
locale: [en, en_GB]
where:
{
_or: [
{ PagesThatFallback: { startsWith: "en-gb" } },
{ Language: { Name: { eq: "en-gb" } }}
]
}
) {
total
items {
Name
Url
Language
{
Name
}
PagesThatFallback
}
}
}
Note, I haven't fully implemented this, so I'll let you know how it goes and any tweaks I make
I know that fallback languages aren't currently supported in Opti Graph, and it will be "soon" (not sure what "soon" means though). Has anyone come up with a workaround for fallback languages yet?