Last active
October 3, 2018 14:54
-
-
Save jraps20/1f04a70ebd5f8fa1415d83d2bc41cf66 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
namespace MyProject.Pipelines | |
{ | |
public class ItemsLookup : HttpRequestProcessor | |
{ | |
public override void Process(HttpRequestArgs args) | |
{ | |
// Shared Data Folder | |
Context.Items.SetLazy(MultisiteConstants.SharedDataFolderItem, () => | |
Context.Database.GetItem(new ID(MultisiteConstants.SharedDataFolderId)) | |
); | |
// Shared Configurations Item | |
Context.Items.SetLazy(MultisiteConstants.SharedDataConfigurationItem, () => | |
GetItemByName(MultisiteConstants.ConfigurationsItemName, Context.Items.Get(MultisiteConstants.SharedDataFolderItem)) | |
); | |
// Shared Global Item | |
Context.Items.SetLazy(MultisiteConstants.SharedDataGlobalItem, () => | |
GetItemByName(MultisiteConstants.GlobalItemName, Context.Items.Get(MultisiteConstants.SharedDataFolderItem)) | |
); | |
// Website Root | |
Context.Items.SetLazy(MultisiteConstants.RootItem, () => Context.Database.Items[Context.Site.RootPath]); | |
// Home Item | |
Context.Items.SetLazy(MultisiteConstants.HomeItem, () => Context.Database.Items[Context.Site.StartPath]); | |
// Local Configurations Item | |
Context.Items.SetLazy(MultisiteConstants.LocalConfigurationsItem, () => | |
GetItemByName(MultisiteConstants.ConfigurationsItemName, Context.Items.Get(MultisiteConstants.RootItem)) | |
); | |
// Local Copyright Settings Item | |
Context.Items.SetLazy(MultisiteConstants.LocalCopyrightSettingsItem, () => | |
GetItemByTemplateId(Templates.CopyrightSettings.ID, Context.Items.Get(MultisiteConstants.LocalConfigurationsItem)) | |
); | |
// Local Global Item | |
Context.Items.SetLazy(MultisiteConstants.LocalGlobalItem, () => | |
GetItemByName(MultisiteConstants.GlobalItemName, Context.Items.Get(MultisiteConstants.RootItem)) | |
); | |
} | |
public static Item GetItemByName(string name, Item parentItem) | |
{ | |
if (parentItem == null) | |
{ | |
Log.Warn(string.Format("Unable to retrieve item by name: {0}, parentItem is null.", name), new object()); | |
return null; | |
} | |
return parentItem.GetChildren() | |
.FirstOrDefault(i => i.Name == name); | |
} | |
public static Item GetItemByTemplateId(ID templateId, Item parentItem) | |
{ | |
if (parentItem == null) | |
{ | |
Log.Warn(string.Format("Unable to retrieve item by template id: {0}, parentItem is null.", templateId.ToString()), new object()); | |
return null; | |
} | |
return parentItem.GetChildren() | |
.FirstOrDefault(i => i.TemplateID == templateId); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment