Reputation: 513
I have used a custom image component which has image field-type ribbon when editing in page editor.
In core db, there are 3 webedit buttons for image which I need to hide/disable:
path: /sitecore/system/Field types/Simple Types/Image/WebEdit Buttons/
buttons: 1. Choose Image 2. Image Properties 3. Clear Image
Also, i am aware that this is possible by overriding Querystate() method but im unsure of its implementation as I am new to CommandState handling.
Instead of going through QueryState , I am trying this
I have set the property "DisableEdit" of image as:
<myImage:PictureFillImage Field="<%# MyImage.Constants.FieldNames.Image %>" DisableEdit="true" ID="UIImage" runat="server"/>
I am using a custom class as:
public class PictureFillImage : Sitecore.Web.UI.WebControls.FieldControl
And i am trying to disable web editing for the image as:
public bool DisableEdit { get; set; }
private Sitecore.Web.UI.WebControls.Image _smlImage;
private Sitecore.Data.Fields.ImageField _smlImageField;
private Sitecore.Web.UI.WebControls.FieldControl _fieldControl;
protected override void OnLoad(EventArgs e)
{
this.DataBind();
}
public override void DataBind()
{
// base.OnLoad(e);
this.Item = this.GetItem();
if ((this.Item != null) && (this.Field != null))
{
Sitecore.Data.Fields.Field field = this.Item.Fields[this.Field];
if (field != null)
{
this._smlImageField = (Sitecore.Data.Fields.ImageField)field;
this._smlImage = new Sitecore.Web.UI.WebControls.Image();
this._smlImage.Field = this.Field;
this._fieldControl = this._smlImage as Sitecore.Web.UI.WebControls.FieldControl;
this._smlImage.ID = this.ID;
this._smlImage.CssClass = this.CssClass;
this._smlImage.Parameters = "all=all";
this._fieldControl.Item = this.Item;
this._smlImage.DisableWebEditing = DisableEdit;
this._fieldControl.DisableWebEditing = DisableEdit;
}
}
base.DataBind();
}
I was hoping that the code would hide the three buttons: "Choose Image", "Image Properties" and "Clear Image" that appear in the floating ribbon in the page editor but I had negative result.
Please help.
Upvotes: 0
Views: 1042
Reputation: 3216
You should override the query state method and return hidden or enabled
public override CommandState QueryState(CommandContext context)
{
// your logic here
//access current item
var item = context.Items[0];
// return either Commandstate.Hidden or Commandstate.Enabled
}
For each button you will have a command class declared so you can customize the behaviour for each button.
You can get access to the current item as well.
There's a good example here on how to overrride the querystate to affect the state of the buttons
https://briancaos.wordpress.com/2010/09/10/unlock-sitecore-items/
Upvotes: 2