Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Sitecore.Pipelines.GetRenderingDatasource;
- using Sitecore.Data;
- using Sitecore.Data.Items;
- using Sitecore.Diagnostics;
- using Sitecore.Sites;
- using Sitecore.Text;
- using System;
- using System.Linq;
- namespace Web.Library.Pipelines
- {
- public class GetQueryableDatasourceLocation
- {
- public void Process(GetRenderingDatasourceArgs args)
- {
- Assert.IsNotNull((object)args, "args");
- foreach (var location in
- new ListString(args.RenderingItem["Datasource Location"]))
- {
- string path = location;
- if (location.StartsWith("./", StringComparison.InvariantCulture) && !string.IsNullOrEmpty(args.ContextItemPath))
- path = args.ContextItemPath + location.Remove(0, 1);
- Item obj = args.ContentDatabase.GetItem(path);
- if (obj != null)
- args.DatasourceRoots.Add(obj);
- else if (location.ToLower() == "./content")
- {
- Item contextItem = args.ContentDatabase.GetItem(args.ContextItemPath, args.ContentLanguage);
- if (contextItem != null)
- {
- Item contentFolder = CreateContentFolder(contextItem);
- args.DatasourceRoots.Insert(0, contentFolder);
- }
- }
- }
- }
- protected Item CreateContentFolder(Item contextItem)
- {
- using (new Sitecore.SecurityModel.SecurityDisabler())
- {
- using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system")))
- {
- TemplateItem folderTemplate = contextItem.Database.GetTemplate(new ID(new Guid(Constants.Templates.Folder)));
- return contextItem.Add("Content", folderTemplate);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment