When my editors click the "insert Sitecore link" button in a rich text editor, I'd like to customize the starting point for the dialogs. For example, on Internal Link it starts at the top "/sitecore" item, and on Media Items it starts at the top of the media library. I'd like to have them start in a location I specify instead, at the very least start at the item I'm working with itself (like in a rendering, specifying the datasource location is ./ to have it relative to the datasource). Is this customization possible, and if so where would I specify those starting points?
Sitecore even doesn't have the ability to configure starting location for the GeneralLink field type out of the box. You can ensure in it, but looking into the implementation of
Sitecore.Shell.Applications.ContentEditor.Link, Sitecore.Kernel. Rich Text Editor button Insert Link uses the same dialog. It means that your solution should contain 2 steps:
- Adding ability to use source for General Link.
- Changing the behavior of the button Insert Link
Part 1: Adding ability to use source for General Link.
If you are using Sitecore SXA, then you are lucky, because SXA extends General Link field type. And you already have the ability to set source in your templates. And dialog will show only items that you have set using query.
If you don't use Sitecore SXA then you have 2 options:
- Implement it by yourself using SXA implementation
Sitecore.XA.Foundation.SitecoreExtensions.CustomFields.FieldTypes.Linkas an example.
- Follow Sitecore General Link Field with Source Query article to add the ability to set and use source field.
As an outcome of this step, you should have the ability to set query into source filed on your templates. And Insert Link dialog in the content editor should show only items that you set in your query.
Part 2: Changing the behavior of the button Insert Link
You need to add a custom button to Sitecore RTE.
It should do exactly the same as what the current Insert Link button does, but with one addition. It should pass an additional URL parameter that will contain your query that points to the starting point. In the case, if you have SXA(or you will use SXA as an example), the URL parameter name is