Sitecore插入规则以确保最多(1)某种类型的儿童

在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(); } } } }