I’m sure others have blogged about doing something similar to the following — I probably have also blogged about this more than once but cannot remember everything I’ve blogged about given that I have a huge number of blog posts — but I figure this will be helpful to folks new to Sitecore or those who have seen this before but need some reminding.
The other day, I had to create a new Link field type that only gives content authors/editors the ability to insert links to Items within the Media Library. The following steps are what I used to make this happen. I didn’t need to write any custom code, and this would also work for other solutions similar to this though keep in mind that this solution will only work within the Content Editor — to make this work in the Experience Editor, you will have to write some custom code which I might show in a future blog post.
Step 1: Duplicate an existing field type.
Here I am duplicating ‘/sitecore/system/Field types/Link Types/General Link’ in the Core database:
Step 2: Delete button items that you don’t need.
I’ve deleted all buttons that are not related to Media library items, and also preserved the Follow and Clear button items:
Step 3: Add a new field using the new type you have created in step 1.
Just add the new field on a template:
Step 4: Go to an item using the template from step 3.
As you can see, only the buttons that you preserved from step 2 are there:
Step 5: Click one of the buttons that you preserved from step 2.
Here, I clicked the ‘Insert media link’ button:
After clicking the ‘Insert’ button from the dialog in step 5, I see that a Media Library Item link was set within this new field:
If you have any comments/thoughts/suggestions on this, please share in a comment.