My goal is to automatically set the datasource of a rendering when an certain rendering is added to the page in the Experience Editor. Since the datasource item is created when the user adds a rendering, I cannot set a static datasource path on the rendering itself.
Currently I have the following partial solution:
public void Process(GetRenderingDatasourceArgs args)
{
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
// ... some code to:
// - detect whether a datasource item should be created
// - create datasource item
// ...
// set CurrentDatasource to the path of the newly added datasource item
args.CurrentDatasource = datasourceItem.Paths.FullPath;
}
}
This pipeline is patched before: Sitecore.Pipelines.GetRenderingDatasource.CheckDialogState, Sitecore.Kernel
This results in the datasource item being created correctly and prefilled in the "Select the Associated Content"-dialog. However, I would like to skip this dialog and set the datasource of the rendering on the page immediately to the item I just created. Any suggestions how I can achieve this?
The dialog: