Field Editor ribbon button bug while in Preview Mode
written by jketchum
|March 2015
During a demo, I was in Preview mode in Page Editor discussing some changes. I unknowingly tried to edit a hidden field using a Field Editor button I created to manage the meta data while in preview mode, and the results were not what I expected.
Not only could I click the ribbon button, I could also see the fields and make it appear as if I could edit them.
Thinking I was in fact in Edit mode, I clicked ok on the popup. I was left with a non-responsive Sitecore.
I had to refresh the page to get the page to respond again.
I created a simple patch for this, where it checks the mode of the page and sets the CommandState to disabled if it is in preview mode.
C# code for the fix:
[Serializable]
public class FieldEditor : Sitecore.Shell.Applications.WebEdit.Commands.FieldEditor
{
public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
return WebUtil.GetQueryString("mode") == "preview" || (context.Items.Length > 0 && context.Items[0] != null && !context.Items[0].Access.CanWrite()) ? CommandState.Disabled : CommandState.Enabled;
}
}
Config file patch:
<sitecore>
<commands>
<command name="webedit:fieldeditor" type="Sitecore.Shell.Applications.WebEdit.Commands.FieldEditor, Sitecore.Client">
<patch:attribute name="type">Namespace.Commands.FieldEditor, Namespace</patch:attribute>
</command>
</commands>
</sitecore>
Questions? Comments? Suggestions? Please don't forget to post them below.