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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Drupal -> Calling CiviCRM field values
Pages: [1]

Author Topic: Drupal -> Calling CiviCRM field values  (Read 1714 times)

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Drupal -> Calling CiviCRM field values
November 07, 2008, 04:41:10 pm
I can't find good documentation on this.

I have custom fields in CiviCRM and I want to use them to determine my content for drupal users.

Blocks:
------

I'm looking for a php script to use civicrm fields for block visibility. 
If civicrm_custom_field= 0 then show block.  (I found a few scripts but they don't work)

Content:
------

I'm looking for the equivalent of {contact.city} (CiviCRM mail tokens) to insert into my site's content.  Is there a drupal php command that does the same to access the current user's fields from the civicrm and allow me to show them on other areas of the site.




Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Drupal -> Calling CiviCRM field values
November 07, 2008, 05:37:26 pm
Quote
Blocks:
------
I'm looking for a php script to use civicrm fields for block visibility.
If civicrm_custom_field= 0 then show block.  (I found a few scripts but they don't work)

I think you can use civicrm_contact_search( &$params ) api's to retrieve the custom data value for logged in User and write your conditional code.

Quote
Content:
------
I'm looking for the equivalent of {contact.city} (CiviCRM mail tokens) to insert into my site's content.  Is there a drupal php command that does the same to access the current user's fields from the civicrm and allow me to show them on other areas of the site.
I guess you will have to manually call CiviCRM api to retrieved the data.

You should check http://wiki.civicrm.org/confluence/display/CRMDOC/Using+CiviCRM+APIs+-+Code+Snippets

HTH

Kurund
Found this reply helpful? Support CiviCRM

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Re: Drupal -> Calling CiviCRM field values
November 08, 2008, 04:14:52 pm
I've been looking at it. 

I can't find the API 2.0 items to retrieve my custom fields I created.  Basically "custom-8" is the field.  (It has a name but drupal uses a number in the profile views.)

This code gives the array of basic contacts, but I can't figure out how to reach the custom fields from my second profile.

<?php
if (module_exists('civicrm')) {
global $user;
civicrm_initialize(true);
require_once 'api/v2/Contact.php';
require_once 'api/UFGroup.php';
$userID = crm_uf_get_match_id( $user->uid );
$retrieve = array( contact_id => $userID  );
$getContact = civicrm_contact_get( $retrieve );

}

?>

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: Drupal -> Calling CiviCRM field values
November 09, 2008, 08:22:01 am

can u try:

Code: [Select]
        $retrieve = array( 'contact_id'             => $userID,
                                   'return.sort_name'  => 1,
                                   'return.custom_8'   => 1,
                           );

        $contact = civicrm_contact_get( $retrieve );
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Re: Drupal -> Calling CiviCRM field values
November 09, 2008, 02:06:10 pm
Thanks!  This seems to work.

<?php
if (module_exists('civicrm')) {
global $user;
civicrm_initialize(true);
require_once 'api/v2/Contact.php';
require_once 'api/UFGroup.php';
$userID = crm_uf_get_match_id( $user->uid );
$retrieve = array( 'contact_id'             => $userID,
                                  'return.sort_name'  => 1,
                                  'return.custom_8'   => 1,
                         );
$contact = civicrm_contact_get( $retrieve);
print $contact['custom_8'];
}

?>

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Drupal -> Calling CiviCRM field values

This forum was archived on 2017-11-26.