Created
January 6, 2016 10:09
-
-
Save jammykam/431084d082b969902b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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