1

As part of our clients requirements, we need to add a dropdown field to the Insert Link dialog in Sitecore. Based on the selected Item in the content editor, this new field needs to query the tree to find the appropriate items to display in the dropdown. The problem I'm running into is that the insertLink dialog doesn't have access to the current item.

On a general link field, when the user clicks the "insert link" link, an ajax call is made to /sitecore/shell/Applications/Content-Editor?id=%7B1F6CECCF-4529-43F5-B6C2-0BE96502E6A7%7D&vs=4&la=en&sc_content=master&fo=%7B1F6CECCF-4529-43F5-B6C2-0BE96502E6A7%7D&ic=Apps%2F48x48%2FPencil.png&he=Content%20Editor&cl=0

As part of the post, the FormData contains __CurrentItem which contains the ID of the selected item in the sitecore tree. Part of the json response from this call is the "ShowModalDialog".

{
"commands": [{
        "command": "RegisterTranslation",
        "value": "Please wait while the Content Editor is loading.",
        "key": "Please wait while the Content Editor is loading."
    }, {
        "command": "SetPipeline",
        "value": "0CF084774D7245F18E5B6C868F035B91"
    }, {
        "command": "ShowModalDialog",
        "value": "/sitecore/shell/Applications/Dialogs/Internal link.aspx?hdl=FFE1AED9A4714489818A0F073EFD3987&ro&la=en&sc_content=master",
        "features": "dialogWidth:685px;dialogHeight:600px;help:no;scroll:auto;resizable:yes;maximizable:yes;closable:yes;center:yes;status:no;header:;autoIncreaseHeight:yes;forceDialogSize:no",
        "response": "1"
    }
]}

As you can see, the ID is not passed along to the Internal Link.aspx.

Is there a Sitecore method somewhere that will return the currently selected item in the Sitecore tree? If not, any ideas on the best way to pass the ID into that dialog?

2

Well, I was able to figure out how to do this. I added a new control source of a class that has Sitecore.Shell.Applications.ContentEditor.Link as a base class. Next I overrode the HandleMessage method. Inside this method I check for the message.name == "contentlink:internallink". When it matches, I call a new method in my class that is a copy of the Insert method found in the Link base class. This is necessary because I needed to override the InsertLink method in order to add the current item to the query string.

The Insert method calls Sitecore.Context.ClientPage.Start. I've modified this call to call my version of the InsertLink method. Inside this method I've added the current item to the urlstring that gets sent to the ShowModalDialog call.

Now the querystring to the Link dialog has my current item on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.