官术网_书友最值得收藏!

Creating a gutter to show unpublished items

In the Content Editor, the left margin of the content tree is known as gutter. This area contains icons that can be used to display the status or type of the corresponding item and icons can be toggled on or off.

Let's create a custom gutter icon to identify unpublished items so that we will be able to know the publishing status of all expanded items very easily.

How to do it…

  1. In the SitecoreCookbook project, create a PublishGutter class in the Gutters folder, and inherit it from the Sitecore.Shell.Applications.ContentEditor.Gutters.GutterRenderer class.
  2. Add enum PublishStatus to show the publishing status as follows:
    enum PublishStatus
    {
      Published, NeverPublished, Modified
    }
  3. Add the CheckPublishStatus() method to know the publishing status of the current item:
    private PublishStatus CheckPublishStatus(Item currentItem)
    {
      Database webDB = Factory.GetDatabase("web");
      Item webItem = webDB.GetItem(currentItem.ID);
      if (webItem == null)
        return PublishStatus.NeverPublished;
      if (currentItem["__Revision"] != webItem["__Revision"])
        return PublishStatus.Modified;
    
      return PublishStatus.Published;
    }
  4. Override the GutterIconDescriptor() method to decide which gutter icon to show for the current item, which we will decide based on the publishing status:
    protected override GutterIconDescriptor GetIconDescriptor(Item item)
    {
      PublishStatus publishStatus = CheckPublishStatus(item);
      if (publishStatus != PublishStatus.Published)
      {
        GutterIconDescriptor desc = new GutterIconDescriptor();
        if (publishStatus == PublishStatus.NeverPublished)
        {
          desc.Icon = "Core2/32x32/flag_red_h.png";
          desc.Tooltip = "Item never published!";
        }
        else
        {
          desc.Icon = "Core2/32x32/flag_yellow.png";
          desc.Tooltip = "Item published but modified!";
        }
        desc.Click = string.Format("item:load(id={0})", item.ID);
    
        return desc;
      }
      return null;
    }
  5. Open the Sitecore desktop and switch the database to core. Open the Content Editor and select the /sitecore/Content/Applications/Content Editor/Gutters item. Under it, create a Publishing Status item using the /Sitecore Client/Content editor/Gutter Renderer template.
  6. In the Field Editor pane, enter field values, as shown in the following image:
    How to do it…
  7. Now, open the Content Editor with the master database. Right-clicking on the left-hand side of the content tree will open a pop-up menu of all gutters, as shown on the left-hand side of the following image. Clicking on the Publishing Status gutter will show gutters with red and yellow flags, as shown on the right-hand side of the the following image:
    How to do it…
  8. The preceding image shows that the Content item has been published but has some modifications to it (marked with a yellow flag). The News item was never published (marked with a red flag) and all other items have been published (no flag).

There's more…

Gutter is very helpful in showing the status (such as Publish, Lock, and Workflow) of multiple items on one screen while navigating to the Content Editor.

Note

Heavier use of gutters may take extra load so the user interaction may get slower.

主站蜘蛛池模板: 上林县| 如皋市| 汉寿县| 怀化市| 资兴市| 镇坪县| 阿尔山市| 车险| 浦江县| 千阳县| 开平市| 贺州市| 高清| 乐平市| 博野县| 城口县| 隆回县| 仲巴县| 忻城县| 札达县| 正宁县| 黄平县| 根河市| 平凉市| 新余市| 安化县| 昭觉县| 池州市| 通海县| 柏乡县| 军事| 台北县| 商丘市| 宝坻区| 台湾省| 阜平县| 八宿县| 桂平市| 永顺县| 西乌珠穆沁旗| 定州市|