I don't know much about bucket location filters, but it looks to be a field on the bucket item. Where you want to start is with the addFromTemplate
pipeline. This is the pipeline that is called when you create an item from a branch. Once you access this pipeline you can gain access to the branch items after it is created.
I used code from Kamsar's Branch Presets project to update my layout datasource paths after creating an item from a branch. This same code can be used in your case. You just want to update Id_Of_Your_Bucket_Item
with the template of you bucket item or some other way of finding it after it was created. And update your query
to whatever you need it to be.
The code
public class AddFromBranchPreset : AddFromTemplateProcessor
{
public override void Process(AddFromTemplateArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));
if (args.Destination.Database.Name != "master") return;
var templateItem = args.Destination.Database.GetItem(args.TemplateId);
Assert.IsNotNull(templateItem, "Template did not exist!");
// if this isn't a branch template, we can use the stock behavior
if (templateItem.TemplateID != TemplateIDs.BranchTemplate) return;
Assert.HasAccess((args.Destination.Access.CanCreate() ? 1 : 0) != 0, "AddFromTemplate - Add access required (destination: {0}, template: {1})", args.Destination.ID, args.TemplateId);
// Create the branch template instance - analogous to base.AddFromTemplate(...)
var newItem = args.Destination.Database.Engines.DataEngine.AddFromTemplate(args.ItemName, args.TemplateId, args.Destination, args.NewId);
// find all rendering data sources on the branch root item that point to an item under the branch template,
// and repoint them to the equivalent subitem under the branch instance
UpdateBucketLocationFilter(newItem, templateItem);
args.Result = newItem;
}
protected virtual void UpdateBucketLocationFilter(Item item, BranchItem branchTemplateItem)
{
var bucketTemplate = new TemplateID(new ID("Id_Of_Your_Bucket_Item"));
var bucketItem = item.Children.FirstOrDefault(x => x.TemplateID == bucketTemplate);
if (bucketItem == null) return;
bucketItem.Editing.BeginEdit();
bucketItem.Fields[Sitecore.Buckets.Util.Constants.DefaultQuery].Value = "your query";
bucketItem.Editing.AcceptChanges();
bucketItem.Editing.EndEdit();
}
}
The patch file
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<group name="itemProvider" groupName="itemProvider">
<pipelines>
<addFromTemplate>
<processor type="YourApp.BranchTemplates.AddFromBranchPreset, YourApp.BranchTemplates" />
</addFromTemplate>
</pipelines>
</group>
</pipelines>
</sitecore>
</configuration>