3

I'm working on a hook to display a users PCPs on a custom contact tab. We use PCPs extensively and it would be great to see any pages the contact owns inside their contact card. (Rather than having to pull up the full list of PCPs in a separate window. I also know that there's a link to PCPs in the soft credit section of the contribution tab - but that's only if there is a contribution to the page.)

I'm able to make a custom tab (using the tabset hook) but am struggling how to actually get content on to the tab.

// 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" );
// $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.
$tabs[] = array( 'id'    => 'mySupercoolTab',
                 'url'   => $url,
                 'title' => 'Contribution Tab Renamed',
                 'weight' => 300 );

But I don't know what to set my own url to AND get content on it. I'm in Wordpress 4.3.1 and Civi 4.6.4. Suggestions?

1

The custom tab contains whatever's at the URL in the url parameter. You can test it out by simply linking to another page on your site.

Once you've confirmed that's working, you should generate a page with civix generate:page, and you can replace the url in your tab with that new page's URL.

  • 1
    Please forgive that this may sound stupid...I'm not entirely sure how to use civix. I have it installed but an unsure how to follow the instructions on the wiki (wiki.civicrm.org/confluence/display/CRMDOC/…) I do have an extensions directory set up but have obviously done it wrong, can you A) give me a better idea of where the var folder should be in reference to the civix folder in my user folder and B) explain which part of the code in each of the section is usable and which part is explanation. It's a little daunting when you're new at command line – RayWright Dec 11 '15 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.