在sitecore中,如果我向主數據庫添加一個新項目(未發佈),它不會顯示有關已發佈狀態的任何指示。如何將新項目標記爲未發佈的項目?
例如,如果用戶添加了10個項目,他可能會感到困惑以找出由他添加的待發布項目。
是否有方法將新添加的項目標識爲未發佈或新建,並在「快速操作欄」中顯示驗證?
在sitecore中,如果我向主數據庫添加一個新項目(未發佈),它不會顯示有關已發佈狀態的任何指示。如何將新項目標記爲未發佈的項目?
例如,如果用戶添加了10個項目,他可能會感到困惑以找出由他添加的待發布項目。
是否有方法將新添加的項目標識爲未發佈或新建,並在「快速操作欄」中顯示驗證?
從來沒有想過這個,但它實際上很容易修復。
我創建了一個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
數據庫中的新裝訂線項目:
圖2:切換回您的Master
數據庫,並通過右鍵單擊排水溝區域來激活排水溝。
圖3:天溝現在顯示您的項目的發佈狀態
從我的頭頂開始它不可用。然而,在覈心數據庫中,還有排水溝的定義等。您可以創建自己的。
儘管存在項目上的「已發佈」字段,但我不確定是否考慮了不同的版本。 也許你可以檢查在主機和網絡(即項目不存在網絡或不同的版本,那麼它即將發佈)的項目之間的差異。
或者,請仔細閱讀以下內容:http://webcmd.wordpress.com/2011/08/31/sitecore-ribbon-that-displays-published-state-of-an-item/ 它會解釋如何檢查項目是否作爲功能區發佈。
更有意義,使用的圖標「人/ 16×16/flag_red.png」爲未公開的項目,只要想到這一點,但不想做出新的截圖;) – 2013-03-02 10:58:53
Awesom!非常感謝這個幫助。 :) – Dhanuka777 2013-03-03 10:37:53