Adding a Page Editor 'Save and Publish' Button

1.1k Views Asked by At

I would like to provide another button beside "Save & Close" button on site Page Editor that will trigger save and publish action once pressed. I went to core and made a copy of "Save & Close" button that I'm planning to modify.

enter image description here

I would call this button "Save & Publish", but now I'm kinda curious if I have to modify javascript to include my custom call (let's say javascript:scSave("myPublish:saveAndPublish"))

I'm following this article to hook into pipeline and complete the action but not sure if that is proper way.

Any advice?

1

There are 1 best solutions below

0
On BEST ANSWER

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.