How can a Tridion command extension find out the command it extends?

♀尐吖头ヾ 提交于 2019-12-02 02:37:21

问题


Tridion's user interface allows you to extend specific commands, which is a great way to modify the behavior of certain existing commands. In the configuration file of the editor this is done with a section like this:

<ext:commands>
  <ext:command name="TextUnderline" extendingcommand="MyTextUnderline"/>
  <ext:command name="TextStrikethrough" extendingcommand="MyTextStrikethrough"/>

I am working on a generic command extension class that can be used to modify the behavior of a number of commands:

<ext:commands>
  <ext:command name="TextUnderline" extendingcommand="MyCommandExtension"/>
  <ext:command name="TextStrikethrough" extendingcommand="MyCommandExtension"/>

So in this second configuration fragment, we have the same MyCommandExtension extending both TextUnderline and TextStrikethrough.

But now in the JavaScript for my MyCommandExtension, how can I determine which command was originally fired?

MyCommandExtension.prototype.isAvailable = function (selection, pipeline) {
  ...
  console.log(this.properties.name);
  ...
};

In this scenario the this.properties.name will be logged as a less-than-useful-but-completely-correct:

"DisabledCommand"

I suspect that the information is available somewhere in the pipeline parameter, but haven't found it yet.

How can I find out the original command from MyCommandExtension?


回答1:


Short answer: I couldn't.

I had to do something similar, and ended up having to extend various commands and set the "current" command as part of my "_execute" call (so I would now call _execute(selection, pipeline, originalCommand) for my command.

N




回答2:


You cannot find out what the original command is. The assumption is that an extending command is specific to the command it extends and so would know which one it is extending. When creating generic extensions that work on different commands, I can see how it might be useful to know what the configuration would be.

Maybe you could add this as an Enhancement Request?

To work around it for now, you could create a base command with your logic - which takes the name of the command that it extends as a parameter. And then create specific classes for each command you which to extend, which just call the base command and pass in the name.

To put it differently, create a BaseExtendingCommand with all of the required methods - and then both a TextUnderlineExtendingCommand and TextStrikethroughExtendingCommand which call the methods on BaseExtendingCommand (and pass in "TextUnderline" and "TextStrikethrough", respectively, as arguments)



来源:https://stackoverflow.com/questions/12410599/how-can-a-tridion-command-extension-find-out-the-command-it-extends

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