Don’t speak I know just what you’re saying – Sitecore SPEAK – Customize General Link with NoFollow Checkbox

I recently had to customize a General Link SPEAK dialog to add a NoFollow checkbox so that we can add a rel=”nofollow” on certain links on the site. At first, I was scared of SPEAK and I did not SPEAK yet! 😉

I will say that SPEAK could be easier thank it is and it would help if it didn’t change for every release. Saying that, my hope is that SPEAK will either evolve or Sitecore will end up changing it entirely. I implemented it in Sitecore 8.2 Update 2 rev.161221.

I started searching on this topic and I did not get many hits on customizing an existing field like General Link. The ones I found useful are listed at the bottom of this post. It was made difficult by the changes to Sitecore in each release. Finally I was able to get a working solution. So here goes.

First and foremost, install Sitecore Rocks Visual Studio Plugin, it will make your life easy.

Connect Sitecore Rocks to your local Sitecore Site. Make sure you test the connection so that Sitecore Rocks can update the server components for its interaction.

Once connected, traverse through the tree to /sitecore/client/Applications/Dialogs/InsertLinkViaTreeDialog.

Open the Design Layout for that Dialog.

Once open you can see the different renderings which make up the Dialog.

WORD OF CAUTION: I hosed my install when I added SPEAK 2 renderings in this dialog. The Dialog displayed and acted differently. So the best way to make sure it will work is to duplicate the renderings currently in the Dialog and set the properties.

Open the properties of the PageCode rendering and note the location for the PageCodeScriptFileName attribute and the value for the PageCodeTypeName. Later on we will be modifying these to get our functionality working.

Next, lets duplicate one of the existing items like Anchor. Each of the fields usually comes with three renderings, one for Row, one for label and field. Lets call them, NoFollowRow, NoFollowTextLbl and NoFollowText.

Since we want a checkbox, we will add a new SPEAK version 1 checkbox by clicking on the Add rendering button up top. Lets call it NoFollowChk.

On NoFollowRow properties lets make sure the PlaceholderKey is set to NameContainer.Content and for the other three renderings, lets set the PlaceholderKey to NoFollowRow.Content.

Now please don’t be that fruit who complains about too much detail. I figured that there are a few steps which seem simple enough but difficult to find/perform if you are not a SPEAK expert.

Here are the property values for each of the renderings.

For Text’s you can either specify on the rendering or provide a datasource to where the text is stored.

Leave the text field for Checkbox empty as we want to use the pretty label in NoFollowTextLbl.

We are going to set the text box to be invisible. We will use it for storage of the checked value.

Now that we have everything setup on the dialog, save the InsertLinkViaTreeDialog.layout item.

Ok now for the dirty part. We need to replace Sitecore.Speak.Applications.InsertLinkDialogTree, Sitecore.Speak.Applications with our custom implementation. Unfortunately we have to go down this route ad the code in Sitecore.Speak.Applications.InsertLinkDialogTree, Sitecore.Speak.Applications cannot be extended or overwritten. Lets get to it.

Use your favorite decompiler to get the output for Sitecore.Speak.Applications.InsertLinkDialogTree, Sitecore.Speak.Applications and create a new class InsertLinkDialogTreeCustom. Here is the complete class from ReSharper (Modified lines are highlighted):

Add the two properties we need.

In the ReadQueryParamsAndUpdatePlaceholders function add the following to send back information stored to the SPEAK component.

The next part is to modify how the fields interact. Open Website\sitecore\shell\client\Applications\Dialogs\InsertLinkViaTreeDialog.js file.

Modify the initialized function to check for the text value in the text field and set the checkbox based on that. Here is the entire file with modifications.

In the insertInternalLinkResult function, add in the mapping from the Class to the variables UI will write as raw value of the General Link field. Also modify the template variable to add in the markup used to generate the output to be stored in the General Link field. Last but not the least is to store the correct Checkbox value in the text field. Boom, this concludes the customization. Now to check out the output.

This only solves half the problem which is how do we get Sitecore backend to show and process the Checkbox for NoFollow. In the next blog post we will look at how to render it using GlassMapper. Here is a video of the functionality.



General Link Dialog InsertLinkViaTreeDialog misses InsertLinkRules after Upgrade to 8.2u2
Extending internal General Link dialog with Checkbox in SPEAK
Extending Sitecore 8.1 – Adding support for anchors in internal links

If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).

no comment

Add your comment

Your email address will not be published.