CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Creating new tab for contact
Pages: [1]

Author Topic: Creating new tab for contact  (Read 2517 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Creating new tab for contact
March 20, 2011, 11:15:20 pm
I have already implemented the hook "mymodule_civicrm_tabs" and successfully added a new tab on every contact.   However, my current implementation uses a URL to my PHP script which returns a snippet of HTML. My PHP script is currently outside the usual file system location for custom civicrm code.

I would like to change my implementation so that the URL points to the usual CiviCRM controller, and I can just create a new view/action.  I was thinking of making the URL something like "civicrm/contact/view/myspecialsummary', "reset=1&snippet=1&force=1&cid=$contactID"

Are there any examples of how I can do this? Where ( and with what name) should I put my PHP file so that the standard CiviCRM controller will find it?

Thanks,
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Creating new tab for contact
March 21, 2011, 01:14:17 am
Hi sarah,

You will need to add an item in the menu (that's drupal/civicrm name for the url to controller). There is a hook to add an entry in it

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmxmlMenu

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Creating new tab for contact
March 21, 2011, 06:59:20 am
I created the file named "pogstone_menus.xml" in the same location as my hook implementation.
It contains the following:
Code: [Select]
<?xml version="1.0" encoding="iso-8859-1" ?>
<menu>
  <item>
     <path>civicrm/contact/financialsummarytab</path>
     <page_callback>CRM_Contact_FinancialSummary::getFinancialSummaryTab</page_callback>
     
  </item>
</menu>

I also created a PHP file at: CRM/Contact/FinancialSummary.php which outputs the information I want to see on the tab.

In my hook implementation,  I have the following:
Code: [Select]
  function pogstone_civicrm_xmlMenu( &$files ) {
    $files[] = dirname(__FILE__)."/pogstone_menus.xml";
}

function pogstone_civicrm_tabs( &$tabs, $contactID ) {
 
    $url = CRM_Utils_System::url( '/civicrm/contact/financialsummarytab' , "reset=1&snippet=1&force=1&cid=$contactID" );
   
    $tabs[] = array( 'id'    => 'mySupercoolTab',
                     'url'   => $url,
                     'title' => 'Financial Summary',
                     'weight' => 2 );
}



When testing this, my new tab appears on the contact record, but when I click it no output is displayed.  I even put an intentional typo in  CRM/Contact/FinancialSummary.php  for testing purposes. It does not seem to be called.

The current contents of file FinancialSummary.php file are:
function getFinancialSummaryTab( ){
  print "<br>test";
 asdad
}


I also called the URL "/civicrm/menu/rebuild&reset=1 " several times for good measure.
Any ideas as to why this function does not get called when I click on the new tab?
« Last Edit: March 21, 2011, 07:01:10 am by sgladstone »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Creating new tab for contact
March 21, 2011, 07:56:34 am

all this is happening via AJAX. u'll need to use firebug and see what XHR calls are being made and what the response is

lots of firebug tutorials on the web

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Creating new tab for contact
March 21, 2011, 09:55:44 am
I should have thought to use firebug, that solved the mystery of why my function was not getting called.

Now that its getting called, I get the error message
"warning: call_user_func(CRM_Contact_FinancialSummary::getFinancialSummaryTab) [function.call-user-func]: First argument is expected to be a valid callback in /sites/all/modules/civicrm/CRM/Core/Invoke.php on line 186. "

What should I put as a callback parameter to my function?

Thanks,
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Creating new tab for contact
March 21, 2011, 10:15:24 am
I'm assuming CRM_Contact_FinancialSummary should be the class that contains your function.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Creating new tab for contact
March 21, 2011, 04:20:33 pm
I got my previous issue solved. My custom tab is now displaying the information I need.

There is one minor warning, which I am trying to figure out how to eliminate:

warning: Missing argument 2 for CRM_Contact_FinancialSummary::getFinancialSummaryTab() in

/CRM/Contact/FinancialSummary.php on line 5.

( CRM_Contact_FinancialSummary is the name of the class I implemented, and "getFinancialSummaryTab()" is the name of my method. )
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Creating new tab for contact
March 21, 2011, 04:29:43 pm
Please ignore my previous post. Everything is working properly now.

Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Creating new tab for contact

This forum was archived on 2017-11-26.