Blog about tips & tricks for CMS enhancement

eric.petersson

Hide the Edit Approval Sequence context menu


As questioned at the forums of Episerver World, there is no included setting for disabling the Approval Definition in Episerver. If not used by your customer, it is quite useless to include it in the context menu of the site tree.

Here is how to disable it. This was made in Episerver CMS 11.5 version.

The code

Add this to your module.config file on the root level of your project - which will let us control the initial request of the Episerver edit mode:

<?xml version="1.0" encoding="utf-8"?>
<module>
  <assemblies>
    <add assembly="EpiserverPlayground" />
  </assemblies>
  <dojo>
    <paths>
      <add name="app" path="Scripts" />
    </paths>
  </dojo>
  <clientModule initializer="app.Initializer">
    <moduleDependencies>
      <add dependency="CMS" type="Require RunAfter" />
    </moduleDependencies>
  </clientModule>
</module>

And then with the help of [lang in Dojo] (https://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html) we will override the built in Episerver "isAvailable" for Approval Context Menu and set it to false instead. Put this in a file called "Initializer.js" under your ~/ClientResources/Scripts/ folder:

define([
    // Dojo
    'dojo/_base/declare',
    "dojo/_base/lang",
    // CMS
    'epi/_Module',
    "epi-cms/content-approval/command/EditApprovalDefinition"
], function (declare, lang, _Module, EditApprovalDefinition) {

    return declare("app.Initializer", [_Module], {

        initialize: function () {
            this._overrideContentApprovalDefinition();
        },
        _overrideContentApprovalDefinition: function () {
            lang.extend(EditApprovalDefinition, {
                _enableContentApprovalMenuContext: EditApprovalDefinition.prototype._enableContentApprovalMenuContext,
                _setEnabledState: function () {
                    this.set("isAvailable", false);
                }
            });
        }
    });
});

The result

The edit approval menu should now be hidden from the context menu: