Adding the Publish and Experience Editor options to the Context Menu on non-SXA solutions

Kamruz Jaman - Solution Architect

29 Sep 2023

Share on social media

We have recently worked on a number of projects, moving customers across from Sitecore XP whilst carrying out an upgrade to the latest versions of Sitecore XM 10.x (the "side-grade"). The customers still get all the power of the Sitecore platform, without the extra overheads of the XP platform and DXP features they were not using. This also has the benefit of savings on their infrastructure costs, since XM uses much fewer services, as well as being easier for the development teams to work with.

However, after working with Sitecore SXA for a while it becomes almost second nature to right click on an item in the Content Editor tree in order to publish the item or edit it in Experience Editor, rather than having to click around on the ribbon.

I had always thought the context menu options were custom SXA functionality, so when I investigated how to bring this functionality across to regular ol' Sitecore sites it was somewhat surprising… 

To take a look at how this is implemented in SXA, head on over to the core database and check the following items:

/sitecore/content/Applications/Content Editor/Context Menues/Default/Page Editor
/sitecore/content/Applications/Content Editor/Context Menues/Default/Publish Item

Glad to see that the item name is still Page Editor 😁

You can see that the Message field specifies a command. We can check showconfig.aspx to check which code implements this.

In a merged config for an instance with SXA installed you will find the following:

<commands>
  <command name="item:publish" type="Sitecore.Shell.Framework.Commands.PublishItem,Sitecore.Kernel"/> 
  <command name="webedit:openexperienceeditor" type="Sitecore.XA.Foundation.Editing.Commands.OpenExperienceEditor, Sitecore.XA.Foundation.Editing" patch:source="Sitecore.XA.Foundation.Editing.config"/>
</commands>


However in a regular non-SXA merged config you will find the following:

<commands>
  <command name="item:publish" type="Sitecore.Shell.Framework.Commands.PublishItem,Sitecore.Kernel" />
  <command name="webedit:openexperienceeditor" type="Sitecore.Shell.Applications.WebEdit.Commands.OpenExperienceEditor, Sitecore.ExperienceEditor" />
</commands>


As you can see, the code for these menu items for Item Publish is pointing to non-SXA classes and dll, but the Experience Editor menu option is using custom SXA code. However when I inspected the code in the SXA implementation vs the stock implementation using dotPeek, the code did not seem very different, at least not specific enough that it was adding something special for this feature.

Let's package these items up from the core database of a SXA based instance and then install the package to a non-SXA instance and see what happens…

And voila, there you have it, we now have the Publish and Experience Editor menu items available, no code or config changes needed! Added bonus that no changes are needed if you are using Publishing Service.

So simple that I'm kind of surprised this has not been implemented in the core platform!

You'll probably want to add these to your own solution, if you're using Unicorn for serialization then add the configs for these items:

<configuration name="Core Menu Items" description="Item Context Menu Items">
  <predicate>
    <include name="Context Menu - Page Editor" database="core" path="/sitecore/content/Applications/Content Editor/Context Menues/Default/Page Editor" />
    <include name="Context Menu - Publish Item" database="core" path="/sitecore/content/Applications/Content Editor/Context Menues/Default/Publish Item" />
  </predicate>
</configuration>


You can download a package of these 2 items from here, this is simply a package of the items from SXA so the guids will be exactly the same too.


Sign up to our newsletter

Share on social media

Kamruz Jaman

Kamruz is a 11-time Sitecore MVP who has worked with the Sitecore platform for more than a decade and has over 20 years of development and architecture experience using the Microsoft technology stack. Kamruz is heavily involved in the Sitecore Community and has spoken at various User Groups and Conferences. As one of the managing partners of Konabos Inc, Kamruz will work closely with clients to ensure projects are successfully delivered to a high standard.


Subscribe to newsletter