Custom Hooks


Custom hooks provide CMS developers with the ability to extend the functionality of a core set of Ingeniux functions. They can streamline content creation or ensure that content contributors don't forget to perform steps. For example, a custom hook can create page-specific default values when the page is created, thereby reducing the data entry required by content contributors.

Customized functions fire when a selected event occurs in the CMS environment. The functions are hooked to the event. For example, a function called by onBeforeCheckOut would occur before the CheckOut event.

Most events have a before trigger and an after trigger. These triggers are in memory on the object that the action affects, and the action isn't saved until all code in the hook completes, successfully. Any action can be interrupted by throwing an error in the hook. If a hook has a script that starts a new action, that action is subordinate to the main action. If an error occurs, all "downstream" actions cease until the error is resolved. For instance, if you use the onNew hook to trigger a check-in for a page, but the script in the onBeforeCheckIn hook throws an error, the check-in fails and the new item isn't created.

Custom hooks are stored in the CustomHooks.cs file. Function skeletons are included in this file and can be fleshed out with scripts that reflect the desired business logic. This file can be opened as part of the API_Extensions_Development_Harness project to enable IntelliSense, but the CMS runs the file, independently. You will find the CustomHooks.cs at [path-to-cms-site-instance]\App_Data\xml\Custom.

Caution
Method calls or property updates trigger custom hook methods, so you must be careful not to create an infinite loop. For example, do not set the value page.Name within the body of the OnRename method; otherwise, this would create an infinite loop.

This section includes: