3

I'm developing an extension and I have to extend the Save/SaveClose/SaveNew button behavior to put some new functionality to the Component Presentations on a Page.

The first part of my solution works fine, but I want to know if it's possible to recover the context in my JS file after the default Tridion command call. The purpose is to get the TCM URI of an element that I've just created. I'll explain with an example (there is my extension code):

Netosone.Extensions.BotonSave.prototype._execute = function BotonSave$_execute(selection, pipeline) {

// SOME FUNCIONALITY
$cme.getCommand("Save")._execute(selection, pipeline);

In summary, I have two questions:

  1. Is it possible to execute more code after the Save command (Tridion) invoke?
  2. Is it possible to recover the TCM URI of an element that I have just created (after the Save command (Tridion) invoke too)?

Thanks in advance!

  • If you set the item you're creating to an object - can you try through item.getId(); – Dylan .. Mark Saunders Jun 12 '17 at 17:18
5

Whenever you need data, you should look to the Model objects -- not the editor, view, HTML, browser URL, or similar.

Remember that the data might be changed through other means and you want your solution to work in all scenarios.

In this case, when a new item is saved for the first time, the model object will raise an "idchange" event with the old (temporary) ID and the new one. Which is exactly what you want.

Example (browser console):

$evt.addEventHandler($display.getItem(), "idchange", function(event) {
  var oldId = event.data.oldId;
  var newId = event.data.newId;
  console.log("The ID of the item has changed from '{0}'' to '{1}'.".format(oldId, newId));
})
2

When you say "I need to extend the Save/SaveClose/SaveNew button behavior", it means you need to extend the commands associated with those buttons. For example for save button, the "save" command need to be extended.

  1. To extend a command, first you need implement your command in JS which is documented here and then you need follow the steps to extend the command explained in the answer here
  2. When you implement the command in JS, you will get the selection object there. So for example you want the selected item in execute method of the Command, the code is below:
_execute: function (selection) {
    // Gets the tcm id of the first item selected 
    var firstItemsTcmID = selection.getItem(0);
}
0

The problem is when you try to create a new element, because if you use the Anguilla Framework with the command $display.getUri(), this doesn't show you a valid TCM because the element has not yet been created.

My solution was to add a eventlistener that fires when the url changes, because when the process of create an element finish, the url changes and put on it a valid TCM at the end of the url. So, there is an example:

window.onhashchange = locationHashChanged;
function locationHashChanged() {
    var tcmNewElement = window.location.valueOf().href.split('#id=')[1];
}

I hope it helps you.

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.