Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flag new items as unpublished items?

Tags:

sitecore

In sitecore, if I add a new item to the master database(Unpublished), it does not show any indication regarding the published state.

For an example, if a user has added 10 items, he might get confused to figureout the items added by him which are pending for publishing.

Is there a way to identify newly added items as unpublished or in new and display a validation in the "Quick action bar"?

like image 662
Dhanuka777 Avatar asked Mar 02 '13 08:03

Dhanuka777


Video Answer


2 Answers

Never thought about this, but it's actually pretty easy to fix.

I created a GutterRenderer that indicates wether an item has been published to at least one, to all, or to none of the publishing targets.

EDIT: Added Click behaviour. When you click the gutter icon, the Publish dialog will be shown for that item.

First I will show you the code that I wrote for this and then I'll show you screenshots of the setup and the result.

Here is the code:

using System.Collections.Generic;
using System.Linq;
using Sitecore;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Globalization;
using Sitecore.Shell.Applications.ContentEditor.Gutters;

namespace ParTech.Library.Gutters
{
  public class PublicationStatus : GutterRenderer
  {
    private readonly ID publishingTargetsFolderId = new ID("{D9E44555-02A6-407A-B4FC-96B9026CAADD}");
    private readonly ID targetDatabaseFieldId = new ID("{39ECFD90-55D2-49D8-B513-99D15573DE41}");

    protected override GutterIconDescriptor GetIconDescriptor(Item item)
    {
      bool existsInAll = true;
      bool existsInOne = false;

      // Find the publishing targets item folder
      Item publishingTargetsFolder = Context.ContentDatabase.GetItem(publishingTargetsFolderId);

      if (publishingTargetsFolder == null)
      {
        return null;
      }

      // Retrieve the publishing targets database names
      List<string> publishingTargetsDatabases = publishingTargetsFolder.GetChildren()
        .Select(x => x[targetDatabaseFieldId])
        .ToList();

      // Check for item existance in publishing targets
      publishingTargetsDatabases.ForEach(delegate(string databaseName)
      {
        if (Database.GetDatabase(databaseName).GetItem(item.ID) != null)
        {
          existsInOne = true;
        }
        else
        {
          existsInAll = false;
        }
      });

      // Return descriptor with tooltip and icon
      string tooltip = Translate.Text("This item has not yet been published");
      string icon = "People/16x16/flag_red.png";

      if (existsInAll)
      {
        tooltip = Translate.Text("This item has been published to all targets");
        icon = "People/16x16/flag_green.png";
      }
      else if (existsInOne)
      {
        tooltip = Translate.Text("This item has been published to at least one target");
        icon = "People/16x16/flag_yellow.png";
      }

      return new GutterIconDescriptor()
      {
        Icon = icon,
        Tooltip = tooltip,
        Click = string.Format("item:publish(id={0})", item.ID)
      };
    }
  }
}

And this is how so set it up and how it will look once it's running:

Figure 1: Create a new Gutter item in the Core database: enter image description here

Figure 2: Switch back to your Master database and activate the Gutter by right-clicking in the gutter area. enter image description here

Figure 3: The Gutter now indicates the publication status of your items enter image description here

like image 113
Ruud van Falier Avatar answered Nov 03 '22 00:11

Ruud van Falier


From the top of my head it's not available out of the box. In the core database however, there's the definitions of the gutter, etc. You could create your own.

There's the 'published' field on items though, but I'm not sure if that takes different versions into account. Maybe you can check the differences between the item in the master and web (i.e. Item doesn't exist or is different version in web, then it's waiting to be published).

Alternatively, have a read through this: http://webcmd.wordpress.com/2011/08/31/sitecore-ribbon-that-displays-published-state-of-an-item/ It'll explain how to check if an item is published as a ribbon.

like image 34
Trayek Avatar answered Nov 03 '22 00:11

Trayek