Skip to content

Instantly share code, notes, and snippets.

@xurizaemon
Created April 26, 2015 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xurizaemon/68adc38790c90ab86f9b to your computer and use it in GitHub Desktop.
Save xurizaemon/68adc38790c90ab86f9b to your computer and use it in GitHub Desktop.

CiviCRM Hooks in Drupal

civicrm_permission()

This hook can supply permissions that the module defines, so that they can be selected on the user permissions page and used to grant or restrict access to actions the module performs. - * documentation

Retrieves permissions from `CRM_Core_Permission::basicPermissions()`` and returns array to Drupal.

civicrm_block_info()

This hook declares to Drupal what blocks are provided by your module and can optionally specify initial block configuration settings. - documentation

Retrieves a list of blocks from CRM_Core_Block::getInfo().

civicrm_block_view()

Return a rendered or renderable view of a block. - documentation

Retrieves block content array from CRM_Core_Block::getContent($delta);.

civicrm_menu()

This hook enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu (usually the Navigation menu). A path and its associated information is commonly called a "menu router item". This hook is rarely called (for example, when modules are enabled), and its results are cached in the database. - documentation

Provides CiviCRM callback handlers for paths civicrm & admin/config/civicrm.

civicrm_page_build()

Add elements to a page before it is rendered. Use this hook when you want to add elements at the page level. For your additions to be printed, they have to be placed below a top level array key of the $page array that has the name of a region of the active theme. - documentation

Actually we use it to insert CiviCRM html-header region to the page header. Not sure why we don't use hook_html_head_alter()?

civicrm_initialize()

Not a hook, but does a lot of work and gets called whenever we wake the beast from its slumber. Looks like every Drupal page callback will trigger this (maybe not if page cached?).

civicrm_metatag_metatags_view_alter()

Alter metatags before being cached. This hook is invoked prior to the meta tags for a given page are cached. - documentation

Drupal will by default strip some CiviCRM page parameters, and we want bots to record civicrm/contribution/transact?reset=1&id=2 not civicrm/contribution/transact

civicrm_links__locale_block()

"Make the language switcher work with civicrm. We override theme_links__locale_block() so that civicrm language switcher links hold the relevant civicrm parameters."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment