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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Adding a custom tab to Contact (Dojo & CiviCRM API)
Pages: [1]

Author Topic: Adding a custom tab to Contact (Dojo & CiviCRM API)  (Read 1416 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Adding a custom tab to Contact (Dojo & CiviCRM API)
July 17, 2007, 05:53:56 pm
We want to add a custom tab to the Contact screen, but without utilising the standard Custom Data UI (because we want to customise the widget which allows us to edit the data).

I have produced a module which adds a new tab to the Contact screen. The tab content is correctly generated, but Dojo rejects the inclusion of the content, instead displaying the message. I'm using Drupal 5 and CiviCRM 1.8.10400.

Code: [Select]
Error loading 'http://x.x.x/drupal/civicrm/contact/view/additional?reset=1&snippet=1&cid=1' (200 OK)
Accessing the same URL directly (copying it from the Dojo error) displays the page as per normal. There's nothing in the HTTP headers I can see which would tell Dojo that the content is invalid, and the result validates OK (once you add a DOCTYPE etc, as with other fragment requests).

This error message made perfect sense when I was getting 403 or 404 errors, but I don't get why it appears also with 200. I'm not familiar with Dojo.

I've attached a sample module which demonstrates how I've got it working thus far. civicrm_contact_extra.info and civicrm_contact_extra.module go in your Drupal modules directory (optionally in a civicrm_contact_extra directory) and ContactAddition.tpl goes in templates/CRM/Contact/Page/View/ or CIVICRM_CUSTOM/CRM/Contact/Page/View/

Getting Dojo to behave is the first step for me.



Secondarily, I feel that my approach to returning the resulting template and then using exit() is not ideal. If I try to use the template mechanism to return the content, Drupal/CiviCRM adds a 403 Forbidden error. I suspect that this is because CiviCRM doesn't recognise the location that has been requested, and so a permissions request from Drupal to authorise the request is rejected. If I was using a proper API call (or using the API call properly!) to tell CiviCRM about this new request location, I expect it should work. But I don't know CiviCRM's internals well enough to be certain of how I should do this.

http://heydon.com.au/node/942 may have some clues, but appears to be for an earlier version of CiviCRM. Gordon Heydon's ecivicrm.module (the only example I can see which adds an extra Contact tab like this) also uses print('');exit(); ... so I did the same.



Third and finally, I'd very much like to get this demonstration module working and post it as sample code for others hoping to take their CiviCRM Contact screen customisations to the next level.

It's my first attempt, so any critical feedback or pointers would be much appreciated - even just where I haven't followed standard Drupal/CiviCRM practice.
« Last Edit: July 17, 2007, 06:21:40 pm by xurizaemon »
@xurizaemon ā— www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Adding a custom tab to Contact (Dojo & CiviCRM API)
July 17, 2007, 06:13:30 pm
(1) is fixed now (yay!). The site resource base was incorrect, and so the JS file in index.tpl wouldn't load, and Dojo reported the error but displayed the response code from the file which had worked.

So I'm onto (2) now - is there any better way for me to add these new URIs to CiviCRM than just using Drupal's _menu hook and then doing exit() once I've done my work? From a look at Gordon's URL (in post above) this was once possible at least.
@xurizaemon ā— www.fuzion.co.nz

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: Adding a custom tab to Contact (Dojo & CiviCRM API)
July 18, 2007, 07:40:17 pm

Chris:

(FYI: Back in Nelson now, so better timezone wise for u!)

With regard to 2, the "exit" is required since we dont want an entire page to be generated, we just want the small portion with the relevant content returned. CiviCRM does the same thing internally by using a GET variable, "snippet=1"

CiviCRM uses drupal's menu system for top level permissioning and uses one function (civicrm_invoke), so we can handle it internally. In your case I think using the drupal menu system is fine (till we figure out a clean way to allow people to extend our invocation scheme (by potentially having all url's processed by a class file of the same path?)

Lets chat more on IRC / IM

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Adding a custom tab to Contact (Dojo & CiviCRM API)

This forum was archived on 2017-11-26.