Created
April 13, 2016 18:53
-
-
Save mikeedwards83/09a7b03bdb6d6e7950a37cd348a656f9 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
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