Sitecore Ribbon that displays published state of an item


To see if an item is published in Sitecore I would normally have to switch to the ‘web’ database and browse to the item. I created a ribbon panel that shows the ‘Status’ of an item in the ‘web’ database from the ‘master’ database.

View of Published Status

It displays the version number published for each language or tells you the item has not been published.

Here’s the code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Shell.Web.UI.WebControls;
using Sitecore.Diagnostics;
using Sitecore.Data.Items;
using Sitecore.Data;

namespace Sitecore.Prototypes.WebControls.ContentEditor.Panels
{
     public class PublishingInfo : RibbonPanel
    {
         public override void Render(System.Web.UI.HtmlTextWriter output, Web.UI.WebControls.Ribbons.Ribbon ribbon, Data.Items.Item button, Shell.Framework.Commands.CommandContext context)
         {
           Assert.ArgumentNotNull(output, "output");
           Assert.ArgumentNotNull(ribbon, "ribbon");
           Assert.ArgumentNotNull(button, "button");
           Assert.ArgumentNotNull(context, "context");
           if (context.Items.Length >= 1)
           {
               Item contextItem = context.Items[0];
               Database database = Sitecore.Configuration.Factory.GetDatabase("web");

               Item item = database.SelectSingleItem(contextItem.ID.ToString());
               
               string htmlOutput = string.Empty;
               if (item != null)
               {
                   
                   foreach (var language in item.Languages)
                   {
                       Item languageVersion = item.Versions.GetLatestVersion(language);
                       if (languageVersion != null && languageVersion.Versions.Count > 0)
                        {
                            htmlOutput += string.Format("<div>{0} - {1}</div>", languageVersion.Version.Number.ToString(), languageVersion.Language.GetDisplayName());
                        }
                   }
                   
               }
               if (htmlOutput == string.Empty)
               {
                   htmlOutput = "This item is not currently published.";
               }

               htmlOutput = string.Format("<div class='scRibbonToolbarText' style='overflow-y:scroll;padding-right: 20px;font-size:80%;'><div style='font-weight:bold'>Published to Web</div>{0}</div>", htmlOutput);

               output.Write(htmlOutput);
           }

           
         }
    }
}

To configure it :
1. Switch to Core database
2. Browse to /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Publish
3. Insert a new /sitecore/templates/System/Ribbon/Panel
4. See the type according to your class name and assembley
sample : Sitecore.Prototypes.WebControls.ContentEditor.Panels.PublishingInfo, Sitecore.Prototypes.WebControls

Advertisements