[Improvement] DataFactory.Instance.GetAncestors() should retain current language

Vote:
 

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.

#75750
Oct 04, 2013 16:11
Vote:
 

I just noticed the same problem. It's definitely a bug.

#79506
Dec 19, 2013 1:10
Vote:
 

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);
        }

    

 

 

#79901
Edited, Jan 09, 2014 13:02
Vote:
 

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.

#114623
Dec 16, 2014 14:39
Vote:
 
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

#133835
Edited, Sep 11, 2015 11:32
Vote:
 
<p>I agree with reasoning that GetAncestors() should return all&nbsp;ancestor items independent of language versions. But why don't return a collection of content links? It is usual when you only need links anyway and if you want to get content items - you manually&nbsp;load them in the desired language. Moreover opposite GetDescendants() method works exactly like that. This change&nbsp;will remove&nbsp;API inconsistency and the need to document edge cases.</p>
#171800
Nov 17, 2016 16:50
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.