rnolen
rnolen

Reputation: 141

AEM - How to tweak activation error message

We are working in an AEM 6.1 environment and have created an activation preprocessor that will stop pages from being activated if certain attributes are not set. That works great but we'd also like to change the error message that's displayed by the activation process when the preprocessor throws a ReplicationExcdeption. Can anyone point me to the code that actually displays the error message?

Upvotes: 1

Views: 336

Answers (1)

dzenisiy
dzenisiy

Reputation: 865

We overrided several functions in SiteAdmin.Actions.js. Copy it from libs folder /apps/cq/ui/widgets/source/widgets/wcm/SiteAdmin.Actions.js or use CQ.Ext.override

We need to override CQ.wcm.SiteAdmin.scheduleForActivation and CQ.wcm.SiteAdmin.internalActivatePage methods.

We do it with using the following code

CQ.wcm.SiteAdmin.internalActivatePage = function(paths, callback) {
    if (callback == undefined) {
        // assume scope is admin and reload grid
        var admin = this;
        callback = function(options, success, response) {
            if (success) admin.reloadPages();
            else admin.unmask();
        };
    }

    preActionCallback = function(options, success, response) {
        if (success) {
            var responseObj = CQ.Util.eval(response);
            if (responseObj.activation) {
                CQ.HTTP.post(
                    CQ.shared.HTTP.externalize("/bin/replicate.json"),
                    callback,
                    { "_charset_":"utf-8", "path":paths, "cmd":"Activate" }
                    );
            } else {
                CQ.wcm.SiteAdmin.preactivateMessage(responseObj);
            }
        }else{
            CQ.Ext.Msg.alert(
                    CQ.I18n.getMessage("Error"), CQ.I18n.getMessage("Could not activate page."));
        }
        admin.unmask();
    };

    CQ.HTTP.get(
            "/apps/sling/servlet/content/preActivateValidator.html?path=" + paths,
            preActionCallback
    );
};

This path /apps/sling/servlet/content/preActivateValidator.html (You can use any other link and extension) returns json with some info about messages, which are parsed in custom method and generates custom error messages CQ.wcm.SiteAdmin.preactivateMessage:

CQ.wcm.SiteAdmin.preactivateMessage = function(responseObj) {
    var message = "";
    var incorrectItems = responseObj.incorrectItems;
    if (responseObj.countOfIncorrectItems > 1) message = message + "s";
    if (responseObj.missingMetadata) {
        message = message + "Please, set \"Programming Type\" for next videos:<br/>";
        var missingMetadataPaths = responseObj.missingMetadata;
        for(var i = 0; i < missingMetadataPaths.length; i++){
            message = message + "<a href=\""+missingMetadataPaths[i].path+".html\">"+missingMetadataPaths[i].path+"</a><br/>";
        }
        message += "<br/>";
    }
    if(message == ""){
        message = "Unknown error.";
    }
    CQ.Ext.Msg.alert(
        CQ.I18n.getMessage("Error"), CQ.I18n.getMessage(message));
}

So you can implement component or servlet which will verify your attributes and will generate JSON.

Upvotes: 0

Related Questions