Вы можете использовать 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](https://i.stack.imgur.com/Si1dK.png)
В конце концов, вы должны настроить этот процессор трубопровода:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<getLookupSourceItems>
<processor patch:before="processor[1]"
type="Website.LookupItemsFromField, Website" />
</getLookupSourceItems>
</pipelines>
</sitecore>
</configuration>
Эй, это действительно трюк! Спасибо за помощь! –