November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
As a workaround I created overloaded extension method.
public static IEnumerable<IContent> GetAncestors(this IContentLoader loader, ContentReference contentReference, ILanguageSelector selector)
{
// NOTE IContentLoader.GetAncestors returns only content in master language!
// Therefore we must retrieve the correct language branch manually
var ancestors = loader.GetAncestors(contentReference);
return ancestors.Select(ancestor => loader.Get<IContent>(ancestor.ContentLink, selector))
.Where(content => content != null);
}
There is some reasoning about the decision to let GetAncestors return the master language, see this thread.
But it could be clearer from the documentation that the master language is selected, I'll try to make sure it is mentioned in the API docs.
public static class GetAncestorsExtension { public static IEnumerable<IContent> GetAncestors(this IContentLoader loader, ContentReference contentReference, ILanguageSelector selector) { // NOTE IContentLoader.GetAncestors returns only content in master language! // Therefore we must retrieve the correct language branch manually var ancestors = loader.GetAncestors(contentReference); return ancestors.Select(ancestor => loader.Get<IContent>(ancestor.ContentLink, selector.Language)) .Where(content => content != null); } }
Had to specify selector.Language to make this work.
Thanks
Whilst DataFactory.Instance.Get<>() and DataFactory.Instance.GetChildren<>() will try to fetch pages in the same language as the current page, DataFactory.Instance.GetAncestors<>() will return pages in the default language only.
I don't know if this is on purpose, but if not then i'm glad to be of service.