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.
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
If you are outside the framework you can use:
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').
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.
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?
>> How can I assign values to CiviCRM forms?
>> 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
>> 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?
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.