In the end I did a combination of Anton's suggestion as well as extending the Sitecore.Shell.Applications.WebEdit.Commands.AddRendering
command.
It turns out that the getPlaceholderRenderings
pipeline is invoked from the GetPlaceholderChromeData processor (as Anton suggested) and the Sitecore.Shell.Applications.WebEdit.Commands.AddRendering
command. Without passing in the context item from the latter it would be be null when clicking the 'Add here' button in the experience editor.
Unfortunately the AddRendering
command is difficult to extend because it's methods are all protected/private static
, so I had to de-compile it and paste the code into a new version adding the following line to the RunGetPlaceholderRenderingsPipeline
method:
placeholderRenderingsArgs.CustomData["CurrentItem"] = Client.GetItemNotNull(context["contextitempath"]);
Then I just needed to add the new command via a config patch:
<commands>
<command name="webedit:addrendering" type="Sitecore.Shell.Applications.WebEdit.Commands.AddRendering, Sitecore.ExperienceEditor">
<patch:attribute name="type">Foundation.RestrictedRenderings.Infrastructure.Commands.AddRendering, Foundation.RestrictedRenderings</patch:attribute>
</command>
</commands>