Search code examples
dojoepiserver

Episerver/CMS & Dojo/Aspect– how to catch revert to publish event in Dojo?


In post Event on "Revert to Published" I found code to "attach" to revertToPublished event.

dojo.require(["dojo/aspect", "epi/dependency"], function(aspect, dependencey) {
    var editingCommands = dependency.resolve("epi.cms.contentEditing.command.Editing");
    aspect.before(editingCommands.revertToPublished, "_execute", function() {
        // TODO: Reverting Content To Published
    });
});

Basically the code is proper and should work but at least in my widget if I set up this in

postCreate: function () {}

does not so the advise method is never called. Neither before nor after method registration works. The around registration works and calls immediately (as it should).

I’m missing something specific, I guess. Sufficient solution is also to be able to check that model is freshly loaded so no property has tracked change.


Solution

  • Code bellow serves the purpose.

    aspect.before(
      dependency.resolve("epi.cms.contentEditing.command.Editing").model,
      "revertToPublished",
      function() {});