PostNuke Help

Previous
Writing Hooks

Home
up

Next
Unregistering Hooks


Registering Hooks

Once your module has hook-capable functions in place they need to be registered on initialisation of the module so that the administrator can configure their applicability, and other modules can access them through the pnModCallHooks() function. This is carried out through use of the pnModRegisterHook() function. This function should be placed within the modname_init() function of your module and given appropriate parameters to register the relevant hook-capable module functions within your module as hooks.

The pnModRegisterHook() function takes a number of parameters, which are explained below:

hookobject

The object for which the hook is to be registered - currently either category, or item, as described above

hookaction

The action for which the hook is to be registered - currently one of create, delete, transform, or display

hookarea

The area that the hook function covers - currently either GUI (for functions that are in pnuser.php and pnadmin.php) or API (for functions that are in pnuserapi.php and pnadminapi.php)

hookmodule

The name of the module in which the hook function exists - normally the name of the module calling this function

hooktype

The type of the hook function - currently either user or admin

hookfunc

The name of the hook function

The pnModRegisterHook() function returns true if the registration was successful, and false if the registration is unsuccessful.

As an example of registering hooks, if you were developing the 'globalid' utility module (which gives every piece of content in PostNuke a separate ID) and had a globalid_admin_create() function which created an entry in the global ID table for this particular piece of content then you would register this as a creation hook. To do this you would use the following lines within globalid_init():

if (!pnModRegisterHook('item',
                       'create',
                       'API',
                       'globalid',
                       'admin',
                       'create)) {
    return false;
}
         

which would register this hook to be called every time a hook-enabled module someone creates an item (a similar but separate call would be needed to register this hook for the creation of categories as well).

The Ratings module that comes with the core PostNuke distribution has detailed comments on registering hooks within a utility module.


Previous
Writing Hooks

Home
up

Next
Unregistering Hooks