Helix Compatible Insert Options

Insert options, and their proper configuration is the crucial part of the solution development. It is the only way how to provide a way to the content editors to create new content.

Unfortunately, regardless that Helix is the current buzzword, still, there are some areas, where Sitecore does not provide out-of-the-box support for the stricter following of Helix principles.

One of them are Insert options configuration.

Generally, there are two ways how to configure Insert options for the specific item (or its template):

  • template standard values
  • item rules

Template standard values are a good place for Insert options definition, but in a dynamical, modular and multisite solution it is not enough and we need a more dynamic way provided by item rules.

So, how the rule-based insert options look? Let’s look on the /sitecore/system/Settings/Rules/Insert Options item:

There is a flat structure, without any separation of owning modules. And if you try to create some subfolders and put rules inside of them, nothing will happen. It is not supported. And it makes a comfortable way to configure structured serializing configuration in Unicorn very hard.

But, fortunately, there is a solution and way how to extend the searching logic and add some structure into.

uiGetMasters pipeline

When Sitecore needs to get a list of the insert options for any item, it internally calls the uiGetMasters pipeline. And this is the place, which we can extend to add support Helix structure in insert options.

Following code represents the sample code of uiGetMasters pipeline:

Code is pretty straightforward – it just traverses a collection of pre-configured folders and adds their insert options rules into the collection for processing.

To make everything working, just a small configuration patch needs to be added into the Sitecore configuration:

And now, we can organize our Insert options in a structured way, with easy configuration of Unicorn serialization.

One thought on “Helix Compatible Insert Options”

Leave a Reply

Your email address will not be published. Required fields are marked *