Wednesday 2 March 2016

Always select Publish Related Items checkbox in publishing dialog

Leave a Comment
Recently I’d stumbled upon a post on Sitecore Community regarding how to make Publish Related Items checkbox always checked based on a specific User Role.

Original question: I need to make 'Publish Related Items' checked every time any content editor publishes an item. It will be nice if I can do it via Roles. But, if I can’t then I would like to default it for every user in Sitecore.

This can be achieved by overriding sitecore\shell\Applications\Dialogs\Publish\Publish.xml form and make PublishRelatedItems checkbox checked and disabled. Below steps illustrates how to make PublishRelatedItems checkbox always checked based on a specific User Role:
  1. Create a new C# class library project and override the OnLoad method of the PublishForm class and add the following code:
    using Sitecore;
    using Sitecore.Diagnostics;
    using Sitecore.Shell;
    using Sitecore.Shell.Applications.Dialogs.Publish;
    using Sitecore.Web;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace SitecoreCustom
        class CustomPublishForm : PublishForm
            public CustomPublishForm()
                : base()
            protected override void OnLoad(System.EventArgs e)
                //Modify role as per your requirement
                if (Sitecore.Context.User.IsInRole("sitecore\\ContentEditor"))
                    base.PublishRelatedItems.Checked = true;
                    base.PublishRelatedItems.Disabled = true;
  2. Compile the solution and put dll in bin folder of website root.
  3. Duplicate Publish.xml file and paste it at \Website\sitecore\shell\Override\Applications\Dialogs\Publish\
  4. Open Publish.xml which we have just duplicated and update Publish Form code-beside class to use our custom code-beside class instead of Sitecore's default class.
    You have to make below change:
    <WizardForm CodeBeside="SitecoreCustom.CustomPublishForm,SitecoreCustom">
    The format is “<namespace>.<class name>, <assembly name>”. For example: SitecoreCustom is namespace, CustomPublishForm is class name and SitecoreCustom is assembly name.
  5. Login into Sitecore with user who is part of sitecore\\ContentEditor role (or any other specific role as per your requirement)
  6. Select an item and try to publish it. You will see that Publish Related Items checkbox is already checked and disabled.
Comments and suggestions are most welcome. Happy coding!


Post a Comment