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 (Moderator: Dave Greenberg) »
  • Accessing a contact from Drupal
Pages: [1]

Author Topic: Accessing a contact from Drupal  (Read 3190 times)

claudiu.cristea

  • Guest
Accessing a contact from Drupal
April 11, 2009, 02:41:30 am
Hi all,

Is there a CiviCRM API exposed in Drupal? In fact I need to load a contact object (or array?) in Drupal (in template.php) that corresponds to a Drupal user ($user->uid)... How do I access the contact data? I there a simple (API) way?

Thanks.
Claudiu

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: Accessing a contact from Drupal
April 11, 2009, 07:23:26 am

check:

http://wiki.civicrm.org/confluence/display/CRMDOC/API+Overview

you will need to use:

civicrm_uf_match_id_get (api/v2/UFGroup.php)
civicrm_contact_get (api/v2/Contact.php)

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

claudiu.cristea

  • Guest
Re: Accessing a contact from Drupal
April 11, 2009, 11:28:25 pm
Thank you... In (Drupal) template.php I put:

Code: [Select]
function mytheme_username($object) {
  civicrm_initialize(true);
  $userID = crm_uf_get_match_id($object->uid);
  $cg = array( 'contact_id' => $userID );
  $ob = civicrm_contact_get( $cg );

  [...]

}

I get this error:
Code: [Select]
Fatal error: Call to undefined function crm_uf_get_match_id() in /var/www/html/sites/all/themes/mytheme/template.php on line 177
I thought that civicrm_initialize(true) should prepare all the environment (loading necessary files, etc.). Is this a bug or I miss something? I used http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets#UsingCiviCRMAPIs-CodeSnippets-GetaCiviCRMuserobject as sample...

claudiu.cristea

  • Guest
Re: Accessing a contact from Drupal
April 12, 2009, 12:43:58 am
Finally using the below code solves the isue:
Code: [Select]
function mytheme_username($object) {
  civicrm_initialize(TRUE);
  global $civicrm_root;
  include_once($civicrm_root . '/api/UFGroup.php');
  $userID = crm_uf_get_match_id($object->uid);
  $cg = array('contact_id' => $userID);
  include_once($civicrm_root . '/api/v2/Contact.php');
  $ob = civicrm_contact_get($cg);

  [...]

}

Note that there is no crm_uf_get_match_id() in "api/v2". It's only in "api"...

Thanks a lot!
Claudiu

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: Accessing a contact from Drupal
April 12, 2009, 07:38:14 am

we've fixed this in 2.2 and ported it to api/v2 (api will be deprecated in a future release)

i assume u r using an older version

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

claudiu.cristea

  • Guest
Re: Accessing a contact from Drupal
April 12, 2009, 10:16:32 am
I'm using 2.2... See the attachment.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Accessing a contact from Drupal

This forum was archived on 2017-11-26.