sitecoresitecore8sitecore8.1

Sitecore to prevent removing component


I have a page that inserts some predefined components in the placeholders, when user creat it (like gallery and header for example).

I also want web masters to give a freedom to insert other possible components to the placeholders around the predefined components, but I want to prohibit somehow to edit/delete the predefined components (gallery and header) from the page.

However, a content editor can add another gallery component (technically possible) to the same page, and delete it if he wants to. But predefined components should just not be touched (at least be removed from the placeholders. In other words - I don't want to have a delete button in the Experience editor next to the predefined components).

There is a way to fully prohibit editing the component rendering, but I still want web masters to insert components by themselves if they want. I just want them to do not modify the components that come when page is created.

As I understand this can be done somethere on the RenderingReference level, but I cannot figure it out how. Could you give a tip please?


Solution

  • Okay, I have found a way to do this. Just in case if somebody will need it.

    First, we need to create a Processor to catche page renderings in the Experience Editor.

    public class CheckLockedComponentsHandler : GetClientActionsChromeData
    {
        public new void Process(GetChromeDataArgs args)
        {
            if (args.ChromeType == "rendering")
            {
                if (args.CustomData["renderingReference"] is RenderingReference rf && !string.IsNullOrEmpty(rf.Settings.Parameters))
                {
                    var rmParams = WebUtil.ParseUrlParameters(rf.Settings.Parameters);
                    args.ChromeData.Custom["editable"] = string.IsNullOrEmpty(rmParams["editable"]) ? "true" : rmParams["editable"];
                }
            }
        }
    }
    

    When, we add a property editable = false when creating a locked component. enter image description here

    And finally we need to register our processor in the configuration

    <pipelines>
        <getChromeData>
                 <processor type="CheckLockedComponentsHandler,MyLib" patch:after="*[last()]"/>
                </processor>
        <getChromeData>
    </pipelines>