Example: Code for the Insert Options pipeline processor to allow folders anywhere

Version: 10.4

Use the following Insert Options pipeline processor code to allow a user to create folders under any item.

RequestResponse
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:

RequestResponse
<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.

Do you have some feedback for us?

If you have suggestions for improving this article,