【问题标题】:How to flag new items as unpublished items?如何将新项目标记为未发布项目?
【发布时间】:2013-03-02 08:17:30
【问题描述】:

在 sitecore 中,如果我将新项目添加到主数据库(未发布),它不会显示任何关于已发布状态的指示。

例如,如果用户添加了 10 个项目,他可能会搞不清楚自己添加的哪些项目有待发布。

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

【问题讨论】:

    标签: sitecore


    【解决方案1】:

    从来没有想过这个,但实际上很容易解决。

    我创建了一个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 数据库中创建一个新的 Gutter 项:

    图 2:切换回您的 Master 数据库并通过右键单击装订线区域来激活装订线。

    图 3:Gutter 现在指示您的项目的发布状态

    【讨论】:

    • 对未发布的项目使用“People/16x16/flag_red.png”图标更有意义,只是想到了这一点,但不想制作新的屏幕截图;)
    • 太棒了!非常感谢您的帮助。 :)
    【解决方案2】:

    在我看来,它不是开箱即用的。然而,在核心数据库中,有排水沟的定义等。您可以创建自己的。

    虽然项目上有“已发布”字段,但我不确定这是否考虑了不同的版本。 也许你可以检查一下master和web中的item之间的差异(即item不存在或者web中的版本不同,然后它正在等待发布)。

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

    【讨论】:

      猜你喜欢
      • 2021-10-21
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 2017-01-13
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多