简体   繁体   中英

Sitecore Rich Text editor customisation of link Insertions

When a user uses the "Insert Link" feature on the RTE to create stories, we get something like...
<a href="link-to-story"><Item-Name-Of-Story</a>

Instead of taking the Item name I would like to use another field called "Headline"
Does anyone know how to do this?...

<a href="link-to-story">Headline-Of-Story</a>

Any help will be much appreciated. Thanks

First of all, you need need to look at this class with Reflector or DotPeek : Sitecore.Shell.Controls.RichTextEditor.InsertLink.InsertLinkForm and to modify it with your own class. You need to modify just this method,I tested and works fine :

   protected override void OnOK(object sender, EventArgs args)
{
  Assert.ArgumentNotNull(sender, "sender");
  Assert.ArgumentNotNull((object) args, "args");
  string displayName;
  string text;
  if (this.Tabs.Active == 0 || this.Tabs.Active == 2)
  {
    Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
    if (selectionItem == null)
    {
      SheerResponse.Alert("Select an item.", new string[0]);
      return;
    }
    else
    {
      displayName = selectionItem["Headline"];
      if (selectionItem.Paths.IsMediaItem)
        text = CustomInsertLinkForm.GetMediaUrl(selectionItem);
      else if (!selectionItem.Paths.IsContentItem)
      {
        SheerResponse.Alert("Select either a content item or a media item.", new string[0]);
        return;
      }
      else
      {
        LinkUrlOptions options = new LinkUrlOptions();
        text = LinkManager.GetDynamicUrl(selectionItem, options);

      }
    }
  }
  else
  {
    MediaItem mediaItem = (MediaItem) this.MediaTreeview.GetSelectionItem();
    if (mediaItem == null)
    {
      SheerResponse.Alert("Select a media item.", new string[0]);
      return;
    }
    else
    {
      displayName = mediaItem.DisplayName;
      text = CustomInsertLinkForm.GetMediaUrl((Item) mediaItem);
    }
  }
  if (this.Mode == "webedit")
  {
    SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(text));
    base.OnOK(sender, args);
  }
  else
    SheerResponse.Eval("scClose(" + StringUtil.EscapeJavascriptString(text) + "," + StringUtil.EscapeJavascriptString(displayName) + ")");
}

After you modify this class you need to modify next file: \\sitecore\\shell\\Controls\\Rich Text Editor\\InsertLink\\InsertLink.xml where you need to change codeBeside section

<CodeBeside Type="Sitecore.Shell.Controls.RichTextEditor.InsertLink.InsertLinkForm,Sitecore.Client"/>

with something like :

<CodeBeside Type="YourNameSpace.YourInsertLinkForm,YourAssembly"/>

The simplest way around this would be to type the desired link text, then select this before clicking 'insert link' - this way your hyperlink will have the text of whatever you entered, instead of defaulting to the item name.

If you want to modify how Sitecore renders links in RTE fields, you would need to modify the <renderField> pipeline - if you search for this in the web.config, you will see the different classes involved here. Using dotPeek you can decompile the Sitecore source to see how this works. Potentially you could then create your own renderField pipeline handler to change the link rendering behaviour and then reference this new class in your web.config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM