Example: Code for the Insert Options pipeline processor to allow folders anywhere
Abstract
Code example that implements the requirement that allows a user to create folders under any item.
Use the following Insert Options pipeline processor code to allow a user to create folders under any item.
namespace Namespace.Pipelines.GetMasters { public class AllowFolderAnywhere { public void Process(Sitecore.Pipelines.GetMasters.GetMastersArgs args) { Sitecore.Data.Items.Item folder = args.Item.Database.Items[Sitecore.TemplateIDs.Folder]; if(!args.Masters.Contains(folder)) { args.Masters.Add(folder); } } } }
Add the processor to the insert options pipeline definition after the existing GetItemMasters
processor and before the existing GetInsertRules
processor:
<uiGetMasters argsType="Sitecore.Pipelines.GetMasters.GetMastersArgs"> <processor mode="on" type="Sitecore.Pipelines.GetMasters.GetItemMasters,Sitecore.Kernel"/> <processor mode="on" type="Namespace.Pipelines.GetMasters.AllowFolderAnywhere,Assembly" /> <processor mode="on" type="Sitecore.Pipelines.GetMasters.GetInsertRules, Sitecore.Kernel"/> <processor mode="on" type="Sitecore.Pipelines.GetMasters.CheckSecurity, Sitecore.Kernel"/> </uiGetMasters>
Note
You can update this example to incorporate the logic to copy insert options from the parent as described in Example: Command template code to copy insert options from the parent item.