What you need to do is define a custom command in App_Config/Commands.config:
<command name="myPublish:saveAndPublish"
type="YourNamespace.YourCommand, YourAssembly" />
Any custom command needs to subclass Sitecore.Shell.Framework.Commands.Command and override the method public override void Execute(CommandContext context)
.
Use your custom command to call the PublishItem command:
public override void Execute(CommandContext context)
{
var publishCommand = new PublishItem();
publishCommand.Execute(context);
}
A few things to look for:
- This has worked for me in Firefox, but not Chrome, where the item is not saved. scSave uses a lot of front-end javascript, so this appears to be a bug with Sitecore's Chrome support.
- Strangely, the syntax
scSave("item:publish")
does not work, but calling PublishComand indirectly from a custom command does work. If anyone figures out why this is, please comment!
- scSave only works when called from a WebEditButton (/sitecore/templates/System/WebEdit/WebEdit Button), not a ribbon button ('/sitecore/templates/System/Ribbon/Large Button') or ('/sitecore/templates/System/Ribbon/Small Button').
- The WebEditButton must be located at the top of the ribbon hierarchy ('/sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Buttons'). If it is placed on one of the chunks (e.g. "New", "Edit", etc.) it will not render.
- When creating a WebEditButton, if you want to control the icon that displays on the Page Editor, you need to set the Data/Icon through Raw Values. Otherwise, the value gets saved to Appearance/Icon, which controls the icon for the content item, not the PageEditor button. This is due to a bug with the Content Editor.