2013-06-21 23 views

回答

1

我們對已克隆的項目顯示警告。訣竅是使用「getContentEditorWarnings」管道:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
     <pipelines> 
      <getContentEditorWarnings> 
       <processor type="Example.OriginalItem, Example" patch:after="processor[@type='Sitecore.Pipelines.GetContentEditorWarnings.Notifications, Sitecore.Kernel']" /> 
      </getContentEditorWarnings> 
     </pipelines> 
    </sitecore> 
</configuration> 

那麼對於這條管道的代碼是:

using Sitecore.Globalization; 
using Sitecore.Pipelines.GetContentEditorWarnings; 

namespace Example 
{ 
    public class OriginalItem 
    { 
     public void Process(GetContentEditorWarningsArgs args) 
     { 
      var item = args.Item; 

      if ((item == null) || item.GetClones().Count() == 0) return; 
      var warning = args.Add(); 
      warning.Title = "This Item has clones"; 
      warning.IsExclusive = false; 
     } 
    } 
} 

不是真的密切相關的問題,但在這個例子中,我們使用的鏈接分貝找到該物品是否有克隆:

public static IEnumerable<Item> GetClones(this Item original) 
{ 
    Assert.ArgumentNotNull(original, "source"); 
    return (from link in Globals.LinkDatabase.GetReferrers(original) 
      select link.GetSourceItem() into clone 
      where ((clone != null) && (clone.Source != null)) && (clone.Source.ID == original.ID) 
      select clone); 
}