Skip to content

Instantly share code, notes, and snippets.

@jammykam
Created January 6, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammykam/431084d082b969902b72 to your computer and use it in GitHub Desktop.
Save jammykam/431084d082b969902b72 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Web.UI.HtmlControls.Data;
namespace MyProject.CMS.Custom.Controls
{
public class QueryableTreelist : Sitecore.Shell.Applications.ContentEditor.TreeList
{
private string _dataSource = string.Empty;
public override string DataSource
{
get
{
if (_dataSource.StartsWith("query:"))
{
if (Sitecore.Context.ContentDatabase == null || base.ItemID == null)
return null;
Item current = Sitecore.Context.ContentDatabase.GetItem(base.ItemID);
Item obj = null;
try
{
obj = Enumerable.FirstOrDefault<Item>((IEnumerable<Item>)LookupSources.GetItems(current, _dataSource));
}
catch (Exception ex)
{
Log.Error("Treelist field failed to execute query.", ex, (object)this);
}
if (obj == null)
return null;
return obj.Paths.FullPath;
}
return _dataSource;
}
set { _dataSource = value; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment