Page Editor explorations

I read this StackOverflow question, and that made me wonder where the field buttons actually come from. I’d never looked into this before, so here goes.

The summary of the question is:

Can we disable the buttons on fields in Sitecore’s Page Editor, not only based on some field on some item, but also based on which field we have?

The buttons are added in the <getChromeData> pipeline. My initial answer to the question was that one could override the Process method in the GetFieldChromeData class, but that struck me as a little extreme. Especially because it’s a Sitecore processor, so if the Sitecore code gets upgraded, the override has to be changed as well.

So then I figured one could add a processor to the pipeline. I added:

<processor type=TestApplication.RemoveButtons, TestApplication/>

Directly after:

<processor type=Sitecore.Pipelines.GetChromeData.GetFieldChromeData, Sitecore.Kernel/>

My RemoveButtons class looks like this:

public class RemoveButtons : GetChromeDataProcessor
{
    public override void Process(GetChromeDataArgs args)
    {
Assert.ArgumentNotNull(args, “args”);
Assert.IsNotNull(args.ChromeData, “Chrome Data”);

        if (“field”.Equals(args.ChromeType, StringComparison.OrdinalIgnoreCase))
{
Field argument = args.CustomData[“field”] asField;
Assert.ArgumentNotNull(argument, “CustomData[\”{0}\”]”.FormatWith(new object[] { “field” }));

            if (argument.Name == “Title” && MainUtil.GetBool(argument.Item[“NeedsToBeCheckedToPersonalize”], false))
            {
args.ChromeData.Commands.RemoveAll(delegate(WebEditButton b)
{
return b.Header == “Personalize”;
});
}
}
}
}

First I’m checking whether it’s a field or placeholder or rendering. After that, I instantiate the field from the CustomData. Then, if the current field is the Title field and the checkbox NeedsToBeCheckedToPersonalize (which is, just to be clear, a random checkbox I added) is ticked, remove all buttons that are Personalize.

The result for the Title field:

Image

And my subtitle field:

Image

The two fields are on the same item, and of the same type (both are single-line text).

Advertisements

One thought on “Page Editor explorations

  1. Pingback: Rules in the Page Editor | Sitecore and such

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s