This documentation refers to an older version of CiviCRM (3.4 / 4.0). View latest version.

Skip to end of metadata
Go to start of metadata
This page refers to CiviCRM 3.4 and 4.0, current STABLE version.

Documentation Search

CiviCRM 3.4 and 4.0 Documentation

Support and Participation

Developer Resources

CiviCRM books!

Make sure to check out the FLOSS Manual Understanding CiviCRM as well! You can also support this project by ordering a hard copy.

Or support us by buying an eBook or hard copy of Using CiviCRM from Packt Publishing.

Here are some notes I would have found useful when I first started working on Drupal and CiviCRM. Hopefuly it will save you a lot of time.

I would like to personally thank Donald Lobo for all his help and assistance when I first started out.

Check out the CiviCRM Architecture Series on the blog for a good orientation to how CiviCRM works from a developer point of view.

General Notes (that can save you a lot of time.)

Drupal keeps a lot of information in the $user object, so it is worth using the print_r() function in PHP to find out what it contains (i.e. print_r($user)).

The same goes for CiviCRM, except that CiviCRM keeps a lot of information in SESSION. Do a print_r($_SESSION) to find out all that it holds.

To access or set information from the SESSION variable within the CiviCRM framework you can use the methods
$this->set( ) and $this->get( ). ($this->set( $varname, $value); or $value = $this->get( $varname ); )

If you are outside the framework you can use:
$session =& CRM_Core_Session::singleton( );
$session->get( 'userID' ); // which is contact id of the user
$session->get( 'ufID' ); // which is the drupal uid (in drupal's case or whatever cms u r using)

When a user logs into Drupal CiviCRM is invoked by the hook_user() function within the civicrm.module file. CivicCRM will then get some information from the database and store it in session. Amongst other things two important pieces of information are $_SESSION[CRM:CiviCRM][CRM:ufID] and $_SESSION[CRM:CiviCRM][CRM:userID], which keeps track of the Drupal user id (uid) and the CiviCRM contact id respectively. (NOTE: the letters 'uf' stand for 'User Framework').

You can see the current (v2.0) database design for CiviCRM at CiviCRM ERD 2.0, and an older schema at CiviCRM ERD 1.7.

This caused me a few headaches ... Make sure old civicrm installs are completed removed from the Drupal module folder. Even if you rename the civicrm folder to civicrm_old it will conflict with the new install since Drupal scans and loads every module that is included in the 'module' folder irrespective of its name.

Use the CRM_Core_Error::debug() function to dump the value of any variable, query result set, etc. (more info on debugging in code)

Drupal specific information.

User login and user registration are handled in the user.module

The function that determines what page to display is user_page (whether to login or register.)

The function user_register($edit) does all the processing for the registration process.

If successful the user_save() function get's invoked and the data is saved to the database.

Here are some questions and answers:

(Nearly all the answers were provided by Don Lobo)

>> How do you figure out if a user is anonymous?

In Drupal ufID == 0 for anonymous user, so you can use the following code.

global $user;
and check $user->uid. If it is equal to 0 then the user is anonymous (or not logged in.)
($user is a drupal object that can be accessed from any Drupal module.)

CiviCRM ignores anonlymous users so if the $_SESSION[CRM:CiviCRM][CRM:ufID] is not set then the user is not logged in. However it is best to check whether a user is logged in or not using the Drupal $user object

>> How can I find out a users username?

global $user;
$username = $user->name;

>> How can I assign values to CiviCRM forms?

$this->assign( 'userName', $user->name );

>> What files get executed by civicrm when a new user registers (or creates a new account) on a Drupal site?

user_hook() function gets called in civicrm.module
Also take a look at the postProcess() function in the CRM/Profile/Form.php file. (This file only get's called by profile form submissions, which contains the registration form)

>> Where are the CiviCRM forms generated?

Basically the buildQuickForm() function in the CRM/Profile/Form.php file

NOTE: CiviCRM uses the HTML_QuickForm package from the Pear repository.

>> How can I turn multiple check boxes into a drop down box.

Fix the setDefaults and postProcess in the CRM/Contact/Form/GroupTag.php file.

>> CiviCRM has a lot of files, how can I figure out which files are being executed?
(In other words which files handle a given URL?)

All CiviCRM pages are managed by the CRM/Core/Invoke.php file, which then invokes other files depending on what needs to be done.

>> When I delete a drupal user and the corresponding contact and then re-register a user with the same email address it seems to create a few problems?

Yes, you will have to manually edit the civicrm_uf_match table and remove the old entry that matches the old Drupal user id with the old CiviCRM contact id.

NB: an issue has been logged against 1.7 for this.

>> How can I delete contacts in CiviCRM?

See How do I delete a contact? in Frequently Asked Questions.

>> How do I insert data into the HEAD tags of a HTML document?

Use the drupal_set_head() function.

  • None