我有一个 sitecore 项目,它是从另一个 sitecore 项目克隆而来的。当我将子项目添加到父项时,我希望它也将项目添加到克隆下。它这样做但我必须手动接受每个更改。我有 250 个克隆!
最佳答案
在this article from sitecore评论区有人问了类似的问题:
When you create a new subitem for an item that has been clones, it seems you have to manually go to each clone and accept that a subitem be created beneath the clone. Is there any way to not have to do this? For a new solution we will have several clones of one source and the customer won't want to go to every single clone and accept a subitem. It would be much easier and user friendly to have subitems always appear in the clones without any questions. The same also applies to instances where content authors has overridden a value in a clone, then a "power author" changes a value in the source item. How can this change be applied to all clones without the clones having to manually accept the change? Cheers
sitecore 发布了带有一些伪代码的回复。基本上这转化为以下内容:
构建一个事件类
public abstract class AcceptCloneNotificationsEventBase<T> where T : Notification
{
protected abstract bool ShouldAcceptNotification(Item item, Item parent);
public void AcceptClone_SavedItem(object sender, EventArgs args)
{
var item = (Item)Event.ExtractParameter(args, 0);
var parent = item.Parent;
foreach (var clone in item.GetClones())
{
foreach (var notification in clone.Database.NotificationProvider.GetNotifications(clone.Uri))
{
if (notification is T && ShouldAcceptNotification(item, parent))
{
notification.Accept(clone);
}
}
}
}
public void AcceptClone_CreateItem(object sender, EventArgs args)
{
var item = (Item)Event.ExtractParameter(args, 0);
var parent = item.Parent;
foreach (var clone in parent.GetClones())
{
foreach (var notification in clone.Database.NotificationProvider.GetNotifications(clone.Uri))
{
if (notification is T && ShouldAcceptNotification(item, parent))
{
notification.Accept(clone);
}
}
}
}
}
我将其构建为一个抽象
类,因此我可以多次使用它。实现看起来像:
public class ImplementationOfBase:
AcceptCloneNotificationsEventBase<FieldChangedNotification>
{
protected override bool ShouldAcceptNotification(Item item, Item parent)
{
return /*filter the event as you see fit here*/;
}
}
注册事件
<events>
<event name="item:added">
<handler type="Namespace.ImplementationOfBase,Namespace" method="AcceptClone_CreateItem"/>
</event>
<event name="item:saved">
<handler type="Namespace.ImplementationOfBase,Namespace" method="AcceptClone_SavedItem"/>
</event>
</events>
关于c# - 无论如何,sitecore 中是否自动接受克隆通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34359090/