1

I created a composite components control for Web Forms. I accomplished it by overriding the RenderLayout pipeline processor Sitecore.Pipelines.RenderLayout.InsertRenderings. The issue I have is that I want the renderings (sublayouts) editing be disabled. In the pipeline, the Editing property of the rendering item is "read only" at run time.

Does any know of a way to programmatically disable the editing ability of the renderings in my composite placeholder?

public class RenderLayout : RenderLayoutProcessor
{
    public override void Process(RenderLayoutArgs args)
    {
        Assert.ArgumentNotNull(args, "args");
        if (Context.Item == null)
        {
            return;
        }

        using (new ProfileSection("Insert renderings into page."))
        {
            InsertRenderingsArgs insertRenderingsArgs = new InsertRenderingsArgs();
            CorePipeline.Run("insertRenderings", insertRenderingsArgs);

            foreach (RenderingReference current in insertRenderingsArgs.Renderings)
            {
                current.RenderingItem.Editable = false; <----HERE
                Context.Page.AddRendering(current);
            }
        }
    }
}
1

Problem

The property doesn't easily let itself override. I was going to suggest forcing the value with reflection, but that won't work. The property is declared like this:

public virtual bool Editable
{
  get
  {
    return this.InnerItem["Editable"] == "1";
  }
}

Workaround

On the bright side, the RenderingItem class follows a well established CustomItem pattern, so a bit of code will go a long way. Declare a new class, NonEditableRenderingItem - like this:

public class NonEditableRenderingItem : RenderingItem
{
    public NonEditableRenderingItem(Item item) : base(item) {}

    public override bool Editable => false;
}

And then your loop like this. A slight bit of reflection necessary to compensate the shortcomings in Sitecore standard libraries ;-)

    foreach (RenderingReference current in insertRenderingsArgs.Renderings)
    {
        var neRenderingItem = new NonEditableRenderingItem(current.RenderingItem.InnerItem);
        current.GetType().GetField("renderingItem", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(current, neRenderingItem);
        Context.Page.AddRendering(current);
    }

Disclaimer. I don't have a Webforms based solution up and running locally, nor the setup required to fully test your issue. But the above should work, in my opinion.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.