Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using Sitecore.Pipelines.GetRenderingDatasource;
  2. using Sitecore.Data;
  3. using Sitecore.Data.Items;
  4. using Sitecore.Diagnostics;
  5. using Sitecore.Sites;
  6. using Sitecore.Text;
  7. using System;
  8. using System.Linq;
  9.  
  10. namespace Web.Library.Pipelines
  11. {
  12. public class GetQueryableDatasourceLocation
  13. {
  14. public void Process(GetRenderingDatasourceArgs args)
  15. {
  16. Assert.IsNotNull((object)args, "args");
  17. foreach (var location in
  18. new ListString(args.RenderingItem["Datasource Location"]))
  19. {
  20. string path = location;
  21. if (location.StartsWith("./", StringComparison.InvariantCulture) && !string.IsNullOrEmpty(args.ContextItemPath))
  22. path = args.ContextItemPath + location.Remove(0, 1);
  23. Item obj = args.ContentDatabase.GetItem(path);
  24. if (obj != null)
  25. args.DatasourceRoots.Add(obj);
  26. else if (location.ToLower() == "./content")
  27. {
  28. Item contextItem = args.ContentDatabase.GetItem(args.ContextItemPath, args.ContentLanguage);
  29. if (contextItem != null)
  30. {
  31. Item contentFolder = CreateContentFolder(contextItem);
  32. args.DatasourceRoots.Insert(0, contentFolder);
  33. }
  34. }
  35. }
  36. }
  37.  
  38. protected Item CreateContentFolder(Item contextItem)
  39. {
  40. using (new Sitecore.SecurityModel.SecurityDisabler())
  41. {
  42.  
  43. using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system")))
  44. {
  45.  
  46. TemplateItem folderTemplate = contextItem.Database.GetTemplate(new ID(new Guid(Constants.Templates.Folder)));
  47. return contextItem.Add("Content", folderTemplate);
  48. }
  49. }
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment