I came across business requirement in Sitecore where for few items we don't need to attached workflow but we want to create new version when we lock edit the item.
I cant apply below setting as it will impact all the items and my workflow will not useful.
<setting name="RequireLockBeforeEditing" value="true"/>
I also gone through stackoverflow question and it has given below solution but not sure on which event it should be.
public Item StartEditing(Item item)
{
Error.AssertObject((object) item, "item");
if (!Settings.RequireLockBeforeEditing || Context.User.IsAdministrator)
return item;
if (this._context.IsAdministrator || StandardValuesManager.IsStandardValuesHolder(item) || !this.HasWorkflow(item) && !this.HasDefaultWorkflow(item) || !this.IsApproved(item))
return this.Lock(item);
Item obj = item.Versions.AddVersion();
if (obj != null)
return this.Lock(obj);
else
return (Item) null;
}
ribbon > Versions > Addbutton? - Marek Musielakitem:editcommand is called everywhere, e.g. not sure about experience editor? - Marek Musielak