sitecore 中有没有办法确保某种类型的项目只能有某种类型项目的 1 个子项?我正在阅读规则引擎食谱,但我没有得到太多细节。
我工作过的一个网站要求特定项目类型下不能存在超过 6 个子项目。我们考虑过使用插入选项规则,但决定放弃这个想法,因为它不能防止复制、移动或复制项目。
相反,我们决定延长item:created
具有专门用于此任务的处理程序的事件。以下是其工作原理的精简示例。一个明显的改进是从父项的字段中获取最大子项限制(当然,仅管理员可见)。您甚至可以在这里利用规则引擎......
public void OnItemCreated(object sender, EventArgs args)
{
var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;
Sitecore.Diagnostics.Assert.IsNotNull(createdArgs, "args");
if (createdArgs != null)
{
Sitecore.Diagnostics.Assert.IsNotNull(createdArgs.Item, "item");
if (createdArgs.Item != null)
{
var item = createdArgs.Item;
// NOTE: you may want to do additional tests here to ensure that the item
// descends from /sitecore/content/home
if (item.Parent != null &&
item.Parent.TemplateName == "Your Template" &&
item.Parent.Children.Count() > 6)
{
// Delete the item, warn user
SheerResponse.Alert(
String.Format("Sorry, you cannot add more than 6 items to {0}.",
item.Parent.Name), new string[0]);
item.Delete();
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)