2

I would like to open a Speak dialog in Experience Editor mode. I have created a command and tied it to a button in core under /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Page Editor.

Here is my command:

namespace Common.Commands
{
    public class OpenDialog : Command
    {
        protected void Run(ClientPipelineArgs args)
        {
            if (args.IsPostBack) return;

            const string url = "/sitecore/client/Your Apps/MyModal?sc_lang=en";
            SheerResponse.ShowModalDialog(url, "1024", "760", string.Empty, true);
            args.WaitForPostBack();
        }
    }
}

SheerResponse.ShowModalDialog is throwing an error when called in Experience Editor mode but does not when used in content editor mode.

  • Does this mean you answered your question below? Just wondering. – Marco Mar 5 '18 at 16:25
  • @Marco it does but there might be an easier way to handle this/a way to do this from a normal command. – Teeknow Mar 5 '18 at 16:25
  • 1
    @Marco Answering your own question is encouraged, but feel free to add different answers, there are usually multiple ways to do things in Sitecore. – jammykam Mar 5 '18 at 23:42
  • 1
    @jammykam I get that. I was wondering why he didn't accept it as answer. With his answer on my initial comment, he's looking for an easier one as it looks like. – Marco Mar 6 '18 at 1:11
  • 1
    You can't accept your own answer for 2 days, just an FYI. – jrap Mar 9 '18 at 19:43
2

I found something to go off of with the validation button in the Experience Editor's ribbon which also opens a modal. Copied that item that represented the validation button and edited some fields in the presentation details of the large button. I had to edit the command which had to point to my javascript command.

Command field presentation details image

I also needed to edit the PageCodeScriptFileName to point to my javascript file.

PageCodeScriptFileName field presentation details image

I made a request because I had some functionality I wanted to do server side (get the url of an item) but if I didn't have that requirement then the added request wouldn't have been necessary.

Button Item Renderings:

Speak js:

define(["sitecore", "/-/speak/v1/ExperienceEditor/ExperienceEditor.js"], function (Sitecore, ExperienceEditor) {
    Sitecore.Commands.OpenModal =
    {
        execute: function (context) {
            ExperienceEditor.PipelinesUtil.generateRequestProcessor("Custom.OpenModal", function (response) {
                var dialogFeatures = "dialogMinWidth: 850px;";
                ExperienceEditor.Dialogs.showModalDialog(response.responseValue.value, "", dialogFeatures, null);
            }).execute(ExperienceEditor.generatePageContext(context, ExperienceEditor.getPageEditingWindow().document));
        }
    };
});

Request:

namespace Common.CustomSitecore.Requests.SharedContent
{
    public class OpenModal : PipelineProcessorRequest<PageContext>
    {
        public OpenModal()
        {
        }

        public override PipelineProcessorResponseValue ProcessRequest()
        {
            var item = base.RequestContext.Item;

            var pipelineProcessorResponseValue = new PipelineProcessorResponseValue()
            {
                Value = new UrlString($"/sitecore/client/Your Apps/MyModal?sc_lang=en&itemUrl={item.GetUrl()}").ToString()
            };

            return pipelineProcessorResponseValue;
        }
    }
}

Request config:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <sitecore.experienceeditor.speak.requests>
      <request name="Custom.OpenModal" type="Common.CustomSitecore.Requests.SharedContent.OpenModal, Common"/>
    </sitecore.experienceeditor.speak.requests>
  </sitecore>
</configuration>

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.