Skip to content

hook_civicrm_alterMenu

Summary

This hook is called when building CiviCRM's list of HTTP routes and should be used when you want to register custom paths or URLS.

Notes

Comparison of Related Hooks

This is one of three related hooks. The hooks:

Applying changes

Menu data is cached. After making a change to the menu data, clear the system cache.

Availability

Added in CiviCRM 4.7.11.

Definition

hook_civicrm_alterMenu(&$items)

Parameters

  • "$items" the array of HTTP routes, keyed by relative path. Each includes some combination of properties:
    • "page_callback": This should refer to a page/controller class ("CRM_Example_Page_Example") or a static function ("CRM_Example_Page_AJAX::foobar").
    • "access_callback": (usually omitted)
    • "access_arguments": Description of required permissions. Ex: array(array('access CiviCRM'), 'and')
    • "ids_arguments": This array defines any page-specific PHPIDS exceptions. It includes any of these three child elements:
      • "json": Array of input fields which may contain JSON data.
      • "html": Array of input fields which may contain HTML data.
      • "exceptions": Array of input fields which are completely exempted from PHPIDS.

Returns

  • void

Example

/** * Add my page to the menu. * * @param array $items */ function EXAMPLE_civicrm_alterMenu(array &$items):void { $items['civicrm/my-page'] = [ 'page_callback' => 'CRM_Example_Page_AJAX::foobar', 'access_arguments' => [['access CiviCRM'], 'and'], ]; }