There's already answer to similar problem on Stack Overflow: https://stackoverflow.com/questions/21452260/sitecore-tree-list-datasource-versionexist
In a nutshell, what you need to do:
Create DataView which will be responsible for filtering non-existing items
LanguageFilteringMasterDataView : MasterDataView
Override method GetChildItems where you can filter out non-existing items
protected override void GetChildItems(ItemCollection items, Item item)
Register data view in configuration under dataviews node
<dataviews>
<dataview name="LanguageFilteredMaster" assembly="sc70" type="sc70.Controls.LanguageFilteringMasterDataView" Parameters=""/>
</dataviews>
and finally create custom TreeList control which will inherit from TreeList and connect your data view there
public class LanguageFilteringTreelist : TreeList
{
private const string DataViewName = "LanguageFilteredMaster";
protected override void OnLoad(EventArgs args)
{
base.OnLoad(args);
var dataContext = this.FindDataContext();
if (dataContext != null)
{
dataContext.DataViewName = DataViewName;
}
}
protected virtual DataContext FindDataContext()
{
if (this.Controls.Count <= 0)
{
return null;
}
var child = this.Controls[0];
return child.Controls.OfType<DataContext>().FirstOrDefault();
}
}
UPDATES from @josedbaez
The solution works on 8.1. The only difference from the original answer (so others know) is the javascript code. You do not need to make that change anymore as Sitecore now appends selected language to html like: <input id="FIELD9318757_all_Language" type="hidden" value="en-CA"> <input id="FIELD9318757_all_Language" type="hidden" value="en-CA">
Do not forget to register your new field type as MultilistField
to the <fieldtypes>
configuration (Found in "App_Config/FieldTypes.config" by default) so that the items referenced by the field are added to Link Database.
e.g. <fieldType name="LanguageFilteringTreelist" type="Sitecore.Data.Fields.MultilistField,Sitecore.Kernel" />