2012-08-29 2 views

답변

6

내가 작업 한 사이트 중 하나는 특정 항목 유형 아래에 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(); 
      } 
     } 
    } 
} 
+0

전체 세부 정보를 공유 할 수 있습니까? 저는 sitecore를 처음 접했고 어디서부터 시작 해야할지 확실하지 않습니다.이 이벤트 처리기는 어디로 이동합니까? –

+1

[Sitecore 이벤트 관련 기사] (http://sdn.sitecore.net/Articles/API/Using%20Events.aspx)가 있습니다. 오래된 것이지만 대부분은 여전히 ​​관련이 있습니다. 기본적으로이 클래스에 대한 참조는 sitecore/events 섹션의 web.config에 추가해야하며 항목이 만들어 질 때마다 실행됩니다. –

+1

또한 참조 예는 다음과 같습니다.'' –

관련 문제