One of the many great features of Sitecore is the ability to give access to edit the content of your website to a wide range of content editors. Further, you can allow specific groups of editors to edit content in specific areas or based on specific templates.
As you get deeper into the customization of access rights, however, you find that there are some common cases that are not covered by the standard security model that Sitecore exposes. For this, we need to add a customization. One such example is the topic of this post.
- Restrict the creation of certain kinds of components in Experience Editor
- Which components are restricted should be customizable
Actually making this customization is relatively straight-forward, though you will need to touch a few places.
Update the SelectRenderingDatasource.xml Dialog
You will need to open the \Website\sitecore\shell\Applications\Dialogs\SelectRenderingDatasource\SelectRenderingDatasource.xml file and change the CodeBeside element’s Type attribute to a custom type that executes some additional checking to limit the functionality of the dialog.
Create Custom SelectRenderingDatasourceForm
Create your custom SelectRenderingDataSourceForm and override the OnLoad function to disable the Create option based on your custom conditions:
A couple things to note about the above code:
- This checks a configurable Sitecore item that is stored at /sitecore/system/Settings/Custom/Experience Editor Settings, but could be adjusted to look up an item by ID, use a config file or setting, or do any number of other checks
- The DisableCreateOption() method is decompiled from Sitecore.Shell.Applications.Dialogs.SelectRenderingDatasource.SelectRenderingDatasourceForm because it is private and therefore cannot be called from a subclass. We’ve made no modifications to its functionality, merely reproduced it in this class for accessibility.
Create Experience Editor Settings Item
Now you’ll need to create the item which stores the list of component datasource templates that are restricted.
Create the template
I recommend the following template:
Name: Experience Editor Settings
- Restricted Components
- Type: TreelistEx
- Source: DataSource=/sitecore/templates/User Defined&IncludeTemplatesForDisplay=Template Folder,Template&IncludeTemplatesForSelection=Template
Create the item
- Under the /sitecore/system/Settings item, create a folder called Custom
- Inside the Custom folder, create an item from your Experience Editor Settings template
- Select the templates of the component datasources of which you’d like to restrict creation access
- Save your changes
After building and deploying your code changes, you should now be able to see your updated dialog with the creation option disabled for the templates you selected in your Experience Editor Settings item: