November Happy Hour will be moved to Thursday December 5th.

Fallback Languages in Optimizely Graph

Vote:
 

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?

#329819
Edited, Sep 13, 2024 14:41
Vote:
 

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";
}
#329821
Sep 13, 2024 16:33
Vote:
 

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
    }
  }
}
#329822
Sep 13, 2024 16:36
Vote:
 

Note, I haven't fully implemented this, so I'll let you know how it goes and any tweaks I make 

#329823
Edited, Sep 13, 2024 16:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.