Sitecore Page Editor Clear General Link field

In Page Editor I  have a general link that I want to edit, but once I set up the source I can’t clear it any more.

To fix this bug we need to follow next steps:

To achieve the described functionality please perform the following steps:
1. Create a custom ‘ClearLink’ class based on the WebEditImageCommand class (Sitecore.Shell.Applications.WebEdit.Commands.WebEditImageCommand, Sitecore.Client).
namespace YourNamespace
{
 using System;
 using Diagnostics;
 using Sitecore.Shell.Applications.WebEdit.Commands;
 using Sitecore.Shell.Framework.Commands;
 using Sites;
 using Web;
 using Web.UI.Sheer;

 /// <summary>
 /// The clear image.
 /// 
 /// </summary>
 [Serializable]
 public class ClearLink : WebEditImageCommand
 {
 /// <summary>
 /// Executes the command in the specified context.
 /// 
 /// </summary>
 /// <param name="context">The context.</param>
 public override void Execute(CommandContext context)
 {
 Assert.ArgumentNotNull((object)context, "context");
 WebEditCommand.ExplodeParameters(context);
 string formValue = WebUtil.GetFormValue("scPlainValue");
 context.Parameters.Add("fieldValue", formValue);
 Context.ClientPage.Start((object)this, "Run", context.Parameters);
 }

 /// <summary>
 /// The run.
 /// 
 /// </summary>
 /// <param name="args">The args.</param>
 protected void Run(ClientPipelineArgs args)
 {
 Assert.ArgumentNotNull((object)args, "args");
 if (string.IsNullOrEmpty(args.Parameters["fieldValue"]))
 {
 SheerResponse.Alert("There is no link to remove.", new string[0]);
 }
 else
 {
 SiteContext siteContext = SiteContextFactory.GetSiteContext(WebEditUtil.SiteName);
 string str1;
 if (siteContext != null)
 {
 using (new SiteContextSwitcher(siteContext))
 str1 = WebEditImageCommand.RenderImage(args, "<link />");
 }
 else
 str1 = WebEditImageCommand.RenderImage(args, "<link />");
 string str2 = args.Parameters["controlid"];
 Assert.IsNotNullOrEmpty(str2, "controlId");
 SheerResponse.SetAttribute("scHtmlValue", "value", str1);
 SheerResponse.SetAttribute("scPlainValue", "value", string.Empty);
 SheerResponse.Eval("scSetHtmlValue('" + str2 + "', false, true)");
 }
 }
 }
}
2. Add a custom command definition to the ‘website\App_Config’Commands.config’ file:
    e.g. <command name=”webedit:clearlink” type=”YourNamespace.ClearLink”/>
3. In the Core database create an item based on the ‘/sitecore/templates/System/WebEdit/WebEdit Button’ template under the /sitecore/system/Field types/Link Types/General Link/WebEdit Buttons item.
And fill the ‘Click’ field with the following value, where ‘webedit:clearlink’ is the name of your custom command which is defined in the Commands.config:
    chrome:field:editcontrol({command:”webedit:clearlink”})
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s