I\'m trying to figure out how I can link a Droplink
to the selected items in a Treelist
.
I have a field Theme
, which is the Tre
You can use the getLookupSourceItems
-pipeline for this. With a Droplink
you can specify a Sitecore query as source. And with the getLookupSourceItems
you can change the source at runtime. The following processor checks the items selected in the Treelist
and create a Sitecore query which includes all the items selected in the 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 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));
}
}
You have to specify which field is your "Source" field within the Droplink
source with fromfield=
:
At the end you need to configure this pipeline processor: