Opening Rich Text Editor in custom field of Sitecore Content Editor

自作多情 提交于 2019-12-08 12:23:40

问题


I'm implementing a custom field in Sitecore for the Content Editor, and I need to be able to open the Rich Text editor and get the data from there. I'm not really sure where to look though, nor how to go about it.


回答1:


Had to decompile the Sitecore.Kernel DLL in order to figure this out.

First thing is to spin off a call from the Context.ClientPage object

So, for my situation:

switch (message.Name)
{
    case "richtext:edit":
        Sitecore.Context.ClientPage.Start(this, "EditText");
        break;
}

You will then need to have a method in your class with the same name as defined in the above Start method. Then, you either start the rich text control if the request isn't a postback, or handle the posted data

protected void EditText(ClientPipelineArgs args)
{
    Assert.ArgumentNotNull(args, "args");
    if (args.IsPostBack)
    {
        if (args.Result == null || args.Result == "undefined")
            return;
        var text = args.Result;
        if (text == "__#!$No value$!#__")
            text = string.Empty;
        Value = text;
        UpdateHtml(args); //Function that executes Javascript to update embedded rich text frame
    }
    else
    {
        var richTextEditorUrl = new RichTextEditorUrl
                                    {
                                        Conversion = RichTextEditorUrl.HtmlConversion.DoNotConvert,
                                        Disabled = Disabled,
                                        FieldID = FieldID,
                                        ID = ID,
                                        ItemID = ItemID,
                                        Language = ItemLanguage,
                                        Mode = string.Empty,
                                        Source = Source,
                                        Url = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx",
                                        Value = Value,
                                        Version = ItemVersion
                                    };
        UrlString url = richTextEditorUrl.GetUrl();
        handle = richTextEditorUrl.Handle;
        ID md5Hash = MainUtil.GetMD5Hash(Source + ItemLanguage);
        SheerResponse.Eval("scContent.editRichText(\"" + url + "\", \"" + md5Hash.ToShortID() + "\", " +
                            StringUtil.EscapeJavascriptString(GetDeviceValue(CurrentDevice)) + ")");
        args.WaitForPostBack();
    }


来源:https://stackoverflow.com/questions/9333617/opening-rich-text-editor-in-custom-field-of-sitecore-content-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!