ASP.NET, CMS

Sitecore Custom Gutter for Publishing Status

Gutter also known as quick action bar, can be seen when you right click on the left bar of the content tree.

Sitecore provides default gutters to know the
Locked items of the user
Workflow state
Broken links
Personalizations
Presentation overridden
Item buckets
Publishing warnings

In addition to these default Gutters, we can create custom Sitecore Gutters.

Steps to Create Custom Sitecore Gutter

1.Create a class which inherits the GutterRenderer.
2.Override the GutterIconDescriptor method in the GutterRenderer class, to set the appropriate icons to the gutter.
3.Switch to core database in Sitecore interface.
4.Create Custom Gutter using the /sitecore/templates/Sitecore Client/Content editor/Gutter Renderer.

Gutter Renderer
Gutter Renderer

5.Populate the Header and Type fields of the Gutter, Header field should contain the name you want to give to the Gutter, Type field should contain the fully qualified class name , the dll which contains the class.
6.Right click on the left side of the Content tree and select your Gutter.

CUSTOM SITECORE GUTTER TO INDICATE PUBLISH STATUS

Logic
Any item can have 3 Publishing states

Never Published:
Check whether the item is present in web database , if not implies the item has never been published.

Published:
Compare the revision fields of the item in master and web databases , if found same implies that latest revision has           been published to web.

Modified:
Compare the revision fields or the Updated fields of the item in master and web databases , difference in revision field       implies that item has been modified since published to web.

Code & Implementation

public class GutterUnpublishedItems : GutterRenderer
    {
        private string CheckPublishStatus(Item DatabaseItem)
        {
            Database Web = Database.GetDatabase("web");
            Item WebItem = Web.GetItem(DatabaseItem.ID);
            if (WebItem == null)
            {
                return "Not Published";
            }
            if (WebItem["__Updated"] != DatabaseItem["__Updated"])
            {
                return "Modified";
            }
            return "Published";
        }
        protected override GutterIconDescriptor GetIconDescriptor(Item item)
        {
            String Status = CheckPublishStatus(item);
            GutterIconDescriptor descriptor = new GutterIconDescriptor();
            if (Status != "Published")
            {
                if (Status == "Not Published") //Checking the Publish status , associating appropriate Icons
                {
                    descriptor.Icon = "Applications/32x32/document_error.png";
                    descriptor.Tooltip = "Item Not Published to web database";
                }
                else
                {
                    descriptor.Icon = "Applications/32x32/document_edit.png";
                    descriptor.Tooltip = "Item has been modified after Publishing";
                }
                descriptor.Click = String.Format("item:load(ID={0})", item.ID);
                return descriptor;
            }
            else
            {
                descriptor.Icon = "Applications/32x32/document_ok.png";
                descriptor.Tooltip = "Item has been Published";
                descriptor.Click = String.Format("item:load(ID={0})", item.ID);
                return descriptor;
            }
        }
    }
Gutter Definition
Gutter Definition

Create Gutter in core database and populate the Header and type fields as stated in step 5.

Now You can see your Gutter when you right-click on the left side of the content tree.

Enable Publish Status Gutter
Enable Publish Status Gutter

Select the Gutter to see your Gutter in Action.

Publish Gutter Status
Publish Status in Gutter

Conclusion:

Sitecore Gutters can be very useful since they visually indicate the state of an item which reduces the extra effort for developers. The above implementation of Sitecore Gutter to indicate the Publish Status of an item comes handy when there is no workflow configured for the items.

About The Author

Leave a Reply

*