How can a Tridion team extension know which team it is expanding?

The Tridion user interface allows you to extend specific commands, which is a great way to change the behavior of some existing commands. In the editor configuration file, this is done with the following section:

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

I am working on a general command extension class that can be used to change the behavior of several commands:

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

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

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

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

In this case, this.properties.name will be registered as less useful, but completely correct:

"DisabledCommand"

I suspect that the information is available somewhere in the pipeline parameter, but not yet found.

How to find out the original command from MyCommandExtension ?

+3
source share
2 answers

Short answer: I could not.

I needed to do something similar, and I had to expand the various commands and set the "current" command as part of my "_execute" call (so I now call _execute(selection, pipeline, originalCommand) for my team.

N

+3
source

You cannot find out what the original command is. The assumption is that the extended team is specific to the team that it is expanding, and therefore will know which one it is expanding. When creating common extensions that work with various teams, I see how it would be useful to know what a configuration is.

Perhaps you could add this as a request for improvement?

To get around this now, you can create a basic command with your logic - which takes the name of the command that it expands as a parameter. And then create specific classes for each command that you want to extend, which simply calls the base command and passes the name.

In other words, create a BaseExtendingCommand with all the necessary methods, and then TextUnderlineExtendingCommand and TextStrikethroughExtendingCommand, which call the methods on BaseExtendingCommand (and pass TextUnderline and TextStrikethrough respectively as arguments)

+1
source

All Articles