I create a new plugin and I try to use hook for adding extra tab in the contents, my question is how to get $contactID?

add_action('civicrm_tabs', ' civitest_civicrm_tabs');

function civitest_civicrm_tabs( &$tabs, $contactID ) {

  // unset the contribition tab, i.e. remove it from the page
  unset( $tabs[1] );

  // let's add a new "contribution" tab with a different name and put it last
  // this is just a demo, in the real world, you would create a url which would
  // return an html snippet etc.
  $url = CRM_Utils_System::url( 'civicrm/contact/view/contribution',
                                "reset=1&snippet=1&force=1&cid=$contactID" );
  $tabs[] = array( 'id'    => 'mySupercoolTab',
                   'url'   => $url,
                   'title' => 'Contribution Tab Renamed',
                   'weight' => 300 );

Thank you



hook_civicrm_tabs is now deprecated and you should use http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tabset.

Also note:

// $url should return in 4.4 and prior an HTML snippet e.g. '<div><p>....';
// in 4.5 and higher this needs to be encoded in json. E.g. json_encode(array('content' => <html form snippet as previously provided>));
// or CRM_Core_Page_AJAX::returnJsonResponse($content) where $content is the html code
// in the first cases you need to echo the return and then exit, if you use CRM_Core_Page method you do not need to worry about this.

The hook_civicrm_tabs is called by CiviCRM and provide the contactID argument. You don't need to use add_action(...) to call the hook.

Your example should work as is if you put it in a CiviCRM extension called civitest.

If you need help getting started with extension development, you can start with CiviCRM Wiki

  • 1
    This depends a bit on how the code is packaged. For a WordPress plugin, one would explicitly register the function using add_action(). For a Civi extension or Drupal module, there's no equivalent to add_action() because everything is based off naming conventions. – Tim Otten Jan 20 '16 at 17:56

Your Answer

