2
votes

Is it possible to use a code behind of a command used for ribbon button in content editor as a request for experience editor button? We want to stick to SPEAK and not make any changes to Sitecore.ExperienceEditor.config.

After creating new button in Experience editor, telling .js to call NewCommand request by

Sitecore.ExperienceEditor.PipelinesUtil.generateRequestProcessor("ExperienceEditor.NewCommand");

that was referenced in Sitecore.ExperienceEditor.Speak.Requests.config as

<request name="ExperienceEditor.NewCommand" type="Sitecore.Starterkit.customcode.MyCommand,MyProject"/>

nothing happens and logs say

ERROR Could not instantiate speak request object, 
name:ExperienceEditor.NewCommand, 
type:Sitecore.Starterkit.customcode.MyCommand,MyProject`

Do we have to import PipelineProcessorRequest as suggested by some tutorials or is there a way to use our existing code?

2

2 Answers

0
votes

Have you seen this blog post on adding custom SPEAK command buttons to Sitecore 8 Experience Editor?

https://doc.sitecore.net/sitecore%20experience%20platform/the%20editing%20tools/customize%20the%20experience%20editor%20ribbon

Otherwise if that doesn't achieve what your looking for, it might be worth trying to standard SPEAK application way of triggering a button, In a SPEAK application you can call a JavaScript function from a button click using this code.

javascript:app.FunctionName();

In the core DB update the click field on your button to call JavaScript with the javascript: prefix. Does this allow you to trigger your JavaScript?

enter image description here

0
votes

I was able to use my existing control using guidelines from:

http://jockstothecore.com/sitecore-8-ribbon-button-transfiguration/

Relevant pieces of the old command:

if (args.IsPostBack)
{
    // act upon the dialog completion
    if (args.Result == "yes")
    {
        Context.ClientPage.SendMessage(this, "item:load(...)");
    }
}
else
{
    // trigger the dialog
    UrlString url = new UrlString(UIUtil.GetUri("control:CopyLanguage"));
    url.Add("id", item.ID.ToString());
    url.Add("lang", item.Language.ToString());
    url.Add("ver", item.Version.ToString());
    SheerResponse.ShowModalDialog(url.ToString(), true);
    args.WaitForPostBack();
}

The redressed command:

define(["sitecore"], function (Sitecore) {
    Sitecore.Commands.ScoreLanguageTools = {
        canExecute: function (context) {
            return true; // we will get back to this one
        },
        execute: function (context) {
            var id = context.currentContext.itemId;
            var lang = context.currentContext.language;
            var ver = context.currentContext.version;

            var path = "/sitecore/shell/default.aspx?xmlcontrol=CopyLanguage" +
                       "&id=" + id + "&lang=" + lang + "&ver=" + ver;

            var features = "dialogHeight: 600px;dialogWidth: 500px;";

            Sitecore.ExperienceEditor.Dialogs.showModalDialog(
                path, '', features, null, 
                function (result) {
                    if (result) {
                        window.top.location.reload();
                    }
                }
            );
        }
    };
});