Sitecore Custom Data Provider doubles language versions?

梦想与她 提交于 2020-01-03 04:15:07

问题


So lately I've been working on a Custom Data Provider for Sitecore and it's really neat and works pretty well until I encountered this:

As you can see I'm receiving double language versions. Even though the GetItemVersions of my DataProvider looks like this:

/// <summary>
/// Used to retrieve version and language information of given item.
/// </summary>
public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
{
    VersionUriList result = null;

    if (itemDefinition.ID == RootItem.RootId)
    {
        // Our root only has 1 version in 1 language.
        result = new VersionUriList { new VersionUri(LanguageManager.GetLanguage("en"), Version.First) };
    }
    else if (CanProcess(itemDefinition.ID))
    {
        // Snipped processing of own items
    }

    return result;
}

So this means that any item that I don't handle I return null. Has anyone seen this behaviour before and knows exactly where to fix this?


回答1:


UPDATE 29/04/2014

Meanwhile I have found an even better way to cure this. In the configuration of a dataprovider you can determine which methods are available like so:

<sitecore>
    <dataProviders>
        <CustomDataProvider type="MyLib.Data.CustomDataProvider, MyLib">
            <disable>*</disable>
            <enable>GetChildIDs</enable>
            <enable>GetParentID</enable>
            <enable>GetItemDefinition</enable>
            <enable>GetItemVersions</enable>
            <enable>GetItemFields</enable>
        </CustomDataProvider>
    </dataProviders>
</sitecore>

For those who are running into the same issue as myself when following the guidelines of the documentation:

They forgot to mention that when you integrate into an existing DB (like the master) that you need to override following method:

/// <summary>
/// We don't store any languages.
/// </summary>
public override LanguageCollection GetLanguages(CallContext context)
{
    return null;
}

Otherwise your dataprovider is somehow smart enough to return the languages and thereby supplying them 2 times effectively to Sitecore causing the issue displayed above. (which breaks TDS)




回答2:


I was having exactly the same problem. Override GetItemVersions and GetLanguages fixed the problem.

public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
        {
            if (return true if the itemDefinition is a item from your db)
            {
                VersionUriList result = new VersionUriList();

                //Add versions on languages you want
                result.Add(LanguageManager.GetLanguage("nl"), Sitecore.Data.Version.First);
                result.Add(LanguageManager.GetLanguage("en"), Sitecore.Data.Version.First);

                return result;
            }
            //itemDefinition is a item from a sitecore db => return null (sc will handle versions of his items)
            return null;
        }

And override GetLanguages to return null as suggested



来源:https://stackoverflow.com/questions/21749313/sitecore-custom-data-provider-doubles-language-versions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!