Follow Field Target – Click through to the Item referenced by a Sitecore Field
Fed up the roundabout way of navigating to the Item referenced in one of Sitecore’s Link and List Field Types in the Content Editor I’ve built a concise Sitecore Marketplace Module that lets you click through to the Item the field is targeting.
Until now, the most effective way was to select Raw Values mode from the View Tab in the Ribbon, copy the field value, unselect Raw Values mode, paste the Guid into the Search box and press return.
Instead, the module I have build displays a Follow link directly above the Field which will take you straight to the Item and it supports all the major link and list field types in Sitecore;
- Grouped Droplink
- Grouped Droplist
It even works well with Multilists, items selected in both columns
I have developed the module to be lightweight, only two code files, minimum impact and work natively within Sitecore so it can be added to all Sitecore instances to help with ease of use.
Droplink and Grouped Droplink
The module makes use of Sitecore’s Menu item template which is added beneath the Field Type definition Item in the Core database. This displays the Follow link above each field when added to an Item. On the click event a Custom Command is made passing the field’s Target value.
Droplink and Group Droplink store their Target value as the Item’s Id so it’s the matter of getting value and using
to get the guid and directing the Content Editor to that Item by telling the Client to load that item;
Multilist and Treelist
Despite both Multilist and Treelist raw values are the Ids the
WebUtil.GetFormValue method does not return the guid so they require significant more effort to work with.
The most effective approach I found is to use the
Form being submitted by the click event in the
HttpRequest. With the
FieldId from the
Command event we can loop through the parameters of the Form to find the Field matching that FieldId.
Oncethe correct field has been found we need to consider which Item has been selected by looking for a parameter matching the FieldId and either Selected or Unselected for a Mulitlist field or Selected and AllSelected for a Treelist field. This denotes which column contains the selected item.
Droplist and Grouped Droplist
As you would expect Droplist and Group Droplist are the hardest to build the Follow functionality for as they both have the Display Name of the Item as the selected value, not the Id. The display name really isn’t enough to go out and search the complete content tree to find the Item and redirect the user to it. There is only one possible one way we can definitely find the right Item – Field’s Source, so lets go get it.
Again, using the
Form submitted in the click event of the
HttpRequest I can loop through and select all fields on the Item that are a Droplist (or a Grouped Droplist). Once we have matching field types we need to consider that more than one Droplist (or Grouped Droplist) is present on the Item so we get a narrower list by selecting only fields whose Sources that contain an Item with that Display Name.
For our narrower list of Droplists (or Grouped Droplists) we need to parse each field’s Source. Again more scenario handling is needed as the Source could be an Item Id, Path or query. But fear note, the code handles it all!
With the source parsed we finally have a list of Strongly Typed Items, not just a display name! Now the easy part, loop through each field’s list of items to find the one matching the name and direct the user to their beloved Item!
And that’s it!
A nice little idea of useful functionality that at first glance is a really simple implementation but under the hood does have some magic to it. I’ll be adding this module to all my Sitecore instances, hope you enjoy!
Full source code is available on GitHub;