Sitecore WebEdit Buttons that Dynamically Set Source Location

When dealing with multiple sites it can be problematic to establish a source for a field (i.e. image, or link) that would not require the content author to browse through a deep folder structure. Even if you can establish a pattern that works, a static source does not have any intelligence on the norms for the user or the area of the particular site they are editing. For example the content team may want to establish a convention that images for Section A of the site belong in Folder X and images in Section B belong in Folder Y. You get the picture.

Consider the following Rich Text field:

The insert link and insert image buttons have no means to establish a reasonable path and instead force the user to browse the entire tree. To make these buttons "smarter", we create a new button implementation that can execute some custom rules.

Custom Insert Image Button

Now we need to patch in the button.

When the user clicks on the insert image button the custom rules engine will run and establish a more appropriate starting location.

This code is supported by a custom rule context. We'll not bore you with the details of each condition and actions (they are mostly out of the box Sitecore), but the context is below.