Custom actions

The Custom actions feature allows users to add customized links to the drop-down menu in the Matrix page header. This feature is available in the _admin mode on the Global Preferences and user group preferences pages. It is not available on an individual user Preferences page.

custom actions location

Custom actions execute snippets of JavaScript code on a site asset to enable a desired behavior. The JavaScript is run within a sandbox. Only the data provided within the currentScreen can be used to determine what to display.

Adding custom actions

Custom actions are created in the Custom Action section of the Global preferences page.

To add a custom action:

  1. Navigate to the Global preferences page.

  2. Find the Custom Action section.

  3. Select Add action.

  4. Enter a name for the custom action in the appropriate field.

  5. Add the JavaScript code into the appropriate field.

  6. Click Save.

To delete a custom action:

  1. Navigate to the Global preferences page.

  2. Find the Custom Action section.

  3. Find the custom action you want to delete

  4. Select the checkbox under the Delete header.

  5. Click Save

Examples

The following code sample (which automatically appears as a reference when configuring custom actions) exposes a currentScreen object that can be used in custom actions:

// let currentScreen = {
//   asset: {
//     id: <asset id>,
//     urls: [<all frontend urls>],
//     type_code: <type code>,
//   }
// }

custom actions javascript

The javascript set by the user will be processed by Matrix and used to render the Custom Action by the object returned:

return {
    "display": [true/false], // whether or not the custom action should be displayed
    "url": "http://example.test", // url link to be rendered
}

Add a link to a guide for standard page assets:

let url = "https://exmple-service.example.test/?assetid=";
if (!currentScreen.asset || !currentScreen.asset.id) {
    return {
        "display": false,
        "url": "",
    };
}

return {
    "display": true,
    "url": "https://exmple-service.example.test/?assetid=" + currentScreen.asset.id,
}

Add a custom action link on a specific asset using ID:

let display = false;
let url = "/metadata-test/metadata/";
if(currentScreen.asset) {
    if(currentScreen.asset.id === 169593) {
        display = true;
        url = url.concat(currentScreen.asset.id);
    }
}

return {
    "display": display,
    "url": url,
}

Use the URL of an asset to determine whether to show the link or not:

let display = false;
const url = "http://example.test/metadata/site-map";

if (!currentScreen.asset) {
  return { display: false };
}

let assetUnderMetadata = currentScreen.asset.urls.filter(function(url) {
  return url.match(/\/metadata/);
}).length > 0;
if (!assetUnderMetadata) {
  return { display: false };
}

return {
    "display": true,
    "url": url,
}

Users can also add a generic link that shows on all asset types:

return {
    "display": true,
    "url":  "http://www.google.com"
}

Hide a custom action on an asset

To force custom action to not be rendered:

return {
    "display": false, // do not display
    "url":  "http://www.example.test"
}

Additional Information

  • Custom action preferences are not available on user assets.

  • Matrix keywords are not available in the code block.