Thursday, March 14, 2019

Adding an SMS Link (href=sms:) to the General Link Field Type in Sitecore


In this blog, I am going to explain how to add a custom SMS Link to the General Link Field Type in Sitecore. I always use this sms functionality in my website, so I thought, why not adding it as a custom type in Sitecore so that I would be able make use of it in rendering it as Sitecore Link Field

In order to add this custom sms link, let me walk you through the steps:

1- Login into Sitecore and go to the Core Database.
2- Add a new item under the following path /sitecore/system/Field types/Link Types/General Link/Menu
In the following screenshot, it is named as "SMS".



3- Fill in a display name for this item (e.g Insert SMS Link). This field value is the text that is displayed when you add a general link field to a template and go to an item of this template to inset a link:


4- Set the message field to: contentlink:smslink(id=$Target). This is the case that would navigate the user to the InsertSMSLink Form when he clicks on "Insert SMS Link".



5- Create a class called "SMSLink". This class is going to open the SMS Link Form popup when you click on "Insert SMS Link" link. It checks for the "Message" value and opens the popup accordingly:


6- Navigate back to the Core database, and go to the following path: /sitecore/system/Field types/Link Types/General Link. Set the value of the "Control" field to : content:SMSLink.

7- Add a new customized config file in order to register the SMSLink Control:

8- Now let us add the xml of how the popup would look like when the user clicks on "Insert SMS Link". This file has to be added to the following path : "/sitecore/shell/Applications/Dialogs". Create a new folder there to place the xml file in.


9- When the user fills in the message, and clicks on Ok, the following code will be executed: Another class is created too as a processor to render the SMS link (RenderSMSLink):

10- In order for this processor to work, you need to patch a configuration for it under the pipelines section:

You are all set now!

This way, we are going to still be able to render the link as an Html Sitecore Link (@Html.Sitecore().Field(Templates.TemplateName.Fields.ItemLink,Item))

Hope this is useful :)

Happy Coding!

2 comments:

  1. I keep getting "Error CS0246 The type or namespace name 'LinkForm' could not be found (are you missing a using directive or an assembly reference?)" for step 9 no matter what I try. My using statements match yours. Any idea what's going on? Was this replaced with something else in Sitecore 9?

    ReplyDelete
  2. Adding an SMS Link (href=sms:) to the General Link Field Type in Sitecore

    Keep sharing..
    Sitecore Development Company

    Sitecore CMS Development Services

    ReplyDelete