2013-03-02 98 views
6

在sitecore中,如果我向主数据库添加一个新项目(未发布),它不会显示有关已发布状态的任何指示。如何将新项目标记为未发布的项目?

例如,如果用户添加了10个项目,他可能会感到困惑以找出由他添加的待发布项目。

是否有方法将新添加的项目标识为未发布或新建,并在“快速操作栏”中显示验证?

回答

18

从来没有想过这个,但它实际上很容易修复。

我创建了一个GutterRenderer,它表示项目是否已发布到至少一个,全部或者没有任何发布目标。

编辑:添加点击行为。当您单击装订线图标时,将显示该项目的“发布”对话框。

首先,我要告诉你,我写了这个代码,然后我会告诉你的设置和结果的截图。

下面是代码:

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) 
     }; 
    } 
    } 
} 

这是怎么回事设置它,以及它是如何将回顾一下,它的运行:

图1:创建在Core数据库中的新装订线项目: enter image description here

图2:切换回您的Master数据库,并通过右键单击排水沟区域来激活排水沟。 enter image description here

图3:天沟现在显示您的项目的发布状态 enter image description here

+2

更有意义,使用的图标“人/ 16×16/flag_red.png”为未公开的项目,只要想到这一点,但不想做出新的截图;) – 2013-03-02 10:58:53

+0

Awesom!非常感谢这个帮助。 :) – Dhanuka777 2013-03-03 10:37:53

3

从我的头顶开始它不可用。然而,在核心数据库中,还有排水沟的定义等。您可以创建自己的。

尽管存在项目上的“已发布”字段,但我不确定是否考虑了不同的版本。 也许你可以检查在主机和网络(即项目不存在网络或不同的版本,那么它即将发布)的项目之间的差异。

或者,请仔细阅读以下内容:http://webcmd.wordpress.com/2011/08/31/sitecore-ribbon-that-displays-published-state-of-an-item/ 它会解释如何检查项目是否作为功能区发布。