Thursday, November 24, 2016

Custom Sitecore Command to Disable or Hide Full Publish Menu Option in Sitecore Content Editor

Recently there was a question raised in Sitecore StackExchange site related to disable Full-Publish option in Sitecore Content Editor for all the Editors access the Content Editor, including Administrator users.

Refer original question http://sitecore.stackexchange.com/questions/2763/how-to-prevent-site-publishing-for-everyone/2766#2766




So, basically question was that hide the "Publish site" option for all the users including Sitecore Administrators, from Content Editor.

There were some good suggestion/answers and a suggestion that I didn't agree.

One option was to set permission on menu item in Core database (i.e. /sitecore/content/Applications/Content Editor/Menues/Publish) will not solve this issue since permission will not effect Administrator users.

 Another option suggested was to delete the Full publish menu item from Sitecore Core database (i.e. /sitecore/content/Applications/Content Editor/Menues/Publish). If there is no other way, this is the final option.

UPDATE:
I learned today by a Sitecore friend (Kamruz) that there is another way to achieve this. That is by using Sitecore Rules Engine. You can refer following post for more info
http://stackoverflow.com/questions/37659935/restrict-sitecore-publishing/37691414#37691414


I had a look into this and created a custom Sitecore command to provide more flexible option for this issue.

First I looked into the Sitecore code related to system:publish command which was associated with this "Site publish" menu item and adjust it to support few options which can be changed using config setting.

Basically this will provide you with a Sitecore setting which you can adjust by changing config include file, with options to

  1. Run the default sitecore publishing operation
  2. Display a warning message and ignore the publishing
  3. Hide the menu item from Content Editor

How to Configure the Custom Command

Step 1:

Copy the code dll (i.e. SitecoreFootsteps.Modules.CustomEditorFullPublishOption.dll file) into <website_root>/bin folder

Code : https://github.com/chaturangar/sitecore-footsteps/blob/master/SitecoreFootsteps.Modules/SitecoreFootsteps.Modules.CustomEditorFullPublishOption/CustomCommand/CustomFullPublish.cs

Step 2:

Place the following Config include file in your includes folder

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <commands>
      <command type="SitecoreFootsteps.Modules.CustomEditorFullPublishOption.CustomCommand.CustomFullPublish,SitecoreFootsteps.Modules.CustomEditorFullPublishOption" name="scfootsteps:customfullpublish"/>
    </commands>
    <settings>
      <!-- values : 
        enabled : works as default sitecore publishing
        disabled : display warning message and doesn't trigger publishing
        hidden : hide the full publish option
        -->
      <setting name="SitecoreFootsteps.EditorFullPublishOption" value="enabled" />
    </settings>
  </sitecore>
</configuration>


Step 3:

Adjust the publish menu item in Core database to point to newly define custom command

Open "/sitecore/content/Applications/Content Editor/Menues/Publish" item in Core database from Content Editor
Change "Message" field value to "scfootsteps:customfullpublish"




Thats it. Custom publish command is now configured and should be working.



Following are the senarios and how command behaves


Senario 1:  SitecoreFootsteps.EditorFullPublishOption setting set to "enabled"

This will work as Default Sitecore full-publish option




Senario 2: SitecoreFootsteps.EditorFullPublishOption setting set to "disabled"

This will display a warning message and skip the full-publish when "Site publish" menu item is clicked




Senario 3: SitecoreFootsteps.EditorFullPublishOption setting is set to "hidden"

This will hide the "Site publish" option from Content Editor menu




You can find the code shared in my github repository :
https://github.com/chaturangar/sitecore-footsteps/tree/master/SitecoreFootsteps.Modules/SitecoreFootsteps.Modules.CustomEditorFullPublishOption

Happy Sitecore!!

No comments:

Post a Comment