2014-09-11 6 views
2

Я пытаюсь выяснить, как я могу связать Droplink с выбранными элементами в Treelist. У меня есть поле Theme, которое является Treelist, а также поле MasterTheme, которое является Droplink.Как связать droplink с Treelist в Sitecore

Я должен быть в состоянии выбрать главную тему в Droplink, которая заполнена выбранными данными из Treelist.

Я довольно новичок в Sitecore, и я не знаком с пользовательскими классами.

ответ

10

Вы можете использовать getLookupSourceItems -pipeline для этого. С помощью Droplink вы можете указать запрос Sitecore как источник. И с getLookupSourceItems вы можете изменить источник во время выполнения. Следующий процессор проверяет элементы, выбранные в Treelist, и создает запрос Sitecore, который включает все элементы, выбранные в Treelist.

public class LookupItemsFromField 
{ 
    private const string FromFieldParam = "fromfield"; 

    public void Process(GetLookupSourceItemsArgs args) 
    { 
     // check if "fromfield" is available in the source 
     if (!args.Source.Contains(FromFieldParam)) 
     { 
      return; 
     } 

     // get the field 
     var parameters = Sitecore.Web.WebUtil.ParseUrlParameters(args.Source); 
     var fieldName = parameters[FromFieldParam]; 

     // set the source to a query with all items from the other field included 
     var items = args.Item[fieldName].Split('|'); 
     args.Source = this.GetDataSource(items); 
    } 

    private string GetDataSource(IList<string> items) 
    { 
     if (!items.Any()) return string.Empty; 

     var query = items.Aggregate(string.Empty, (current, itemId) => current + string.Format(" or @@id='{0}'", itemId)); 
     return string.Format("query://*[{0}]", query.Substring(" or ".Length)); 
    } 
} 

Вы должны указать, какое поле ваше поле «Источник» в Droplink источника с fromfield=<SourceField>:

enter image description here

В конце концов, вы должны настроить этот процессор трубопровода:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <pipelines> 
     <getLookupSourceItems> 
     <processor patch:before="processor[1]" 
        type="Website.LookupItemsFromField, Website" /> 
     </getLookupSourceItems> 
    </pipelines> 
    </sitecore> 
</configuration> 
+0

Эй, это действительно трюк! Спасибо за помощь! –