Mike Robbins

Sitecore Developer Blog

Follow me on GitHub

Sitecore Save and Publish Button

I've noticed a common question with teaching new content editors how to create and publish content in Sitecore. "I've created my content and saved it, how do i get the content live on the site"

As we know saving content only writes the item to the Master database so the content appears in a draft status. The content editor then needs to publish the content to the web database for it to appear on the web site.

Some Sitecore instances don't take advantage of workflow because the client doesn't want or need it. In these cases the current method of saving the content and then navigating to the Publishing tab in the ribbon and clicking the publish button seems a little long winded.

Current Sitecore Content Editor Ribbon

Current Ribbon

This made me think of my umbraco days, umbraco has a save button to place content into preview mode. It also has a save and publish button, I wondered if I could replicate this idea within Sitecore.

Within Sitecore it's easy to extend the ribbon in the content editor. The ribbon is controlled by items created within the content editor section of the core database.

I wanted to replicate exactly what the save and publish buttons did. The button commands are controlled by the Commands.config in the app_config folder. This shows me which classes in the Sitecore Kernel class were used for the commands using dependency injection.

commands.config

commands.config

Using the Commands.Config its easy to find out which classes are responsible for functions within the content editor. Using this i was able to find the classes responsible for the save action and for the publish action. Using JustDecompile (an excellent DLL decompiler) with the Sitecore kernel and the namespace information taken from the commands.config I was able to extract the code for the save command and the publish command.
It was an easy task for then create a new class implementing the Command class and replicating both the save and the publish command code together in the same class and register the command to a button in the content editor and extending the Commands.Config to point at my new class..

mike robbins commands config

Extending Commands Config

View the Package on Sitecore Marketplace View

Source Code GitHub