Skip to content

Instantly share code, notes, and snippets.

@mikeedwards83
Created April 13, 2016 18:53
Show Gist options
  • Save mikeedwards83/09a7b03bdb6d6e7950a37cd348a656f9 to your computer and use it in GitHub Desktop.
Save mikeedwards83/09a7b03bdb6d6e7950a37cd348a656f9 to your computer and use it in GitHub Desktop.
public class PageContentItemsView : BucketDataView
{
public const string HomePath = "/sitecore/content/MySite3/Home";
private const string XmlControlKey = "xmlcontrol";
private const string SelectRenderingDatasource = "Sitecore.Shell.Applications.Dialogs.SelectRenderingDatasource";
protected PageContentItemsService ContentItemService
{
get; set;
}
public PageContentItemsView()
{
ContentItemService = new PageContentItemsService();
}
protected override void GetChildItems(ItemCollection items, Item item)
{
base.GetChildItems(items, item);
if (!PathCheck(item))
{
return;
}
for (int i = items.Count - 1; i >= 0; i--)
{
if (ContentItemService.IsPageContentItemsFolder(items[i]))
{
var folder = items[i];
items.Remove(i);
if (IsDataSource() || ContentItemService.ShowPageContentItems)
{
items.Insert(0, folder);
}
}
}
}
protected virtual bool PathCheck(Item item)
{
return item.Paths.Path.StartsWith(HomePath);
}
protected virtual bool IsDataSource()
{
if (HttpContext.Current != null)
{
var request = HttpContext.Current.Request;
var urlQuery = HttpUtility.ParseQueryString(request.Url.Query ?? String.Empty);
var urlReferrerQuery =
HttpUtility.ParseQueryString(request.UrlReferrer == null
? String.Empty
: request.UrlReferrer.Query ?? String.Empty);
var isDataSourceSelection = urlQuery[XmlControlKey] == SelectRenderingDatasource ||
urlReferrerQuery[XmlControlKey] == SelectRenderingDatasource;
return isDataSourceSelection;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment