Upcoming Events
NYC CiviCRM Meeting - March 2010
March 16th, 2010
This next NYC meetup will feature a case study (TBD), group discussions and a (more...)
San Francisco CiviCRM Meetup - March 2010
March 24th, 2010
Come meet others from the Bay Area who are interested in, using or developing (more...)
Campaigning Camp in Oxford, UK
March 25th, 2010
Free (with lunch and tea break included!) CiviCRM/Drupal and Plone two-track (more...)
CiviCRM Seminar - Dublin
March 25th, 2010
MTL Software Solutions are hosting a free seminar at The IBOA, Stephen
St (more...)
CiviCRM User Training - Atlanta (pre NTC)
April 7th, 2010
This full-day hands-on training session is aimed at non-profit staff and (more...)
Configuring, Customizing and Extending CiviCRM - San Francisco (before DrupalCon SF)
April 18th, 2010
This hands-on 1-day training session is targeted at administrators, integrators (more...)
CiviCRM User Training - San Francisco (before DrupalCon SF) This full-day hands-on training session is aimed at non-profit staff and (more...)
April 18th, 2010
CiviCon San Francisco 2010
April 22nd, 2010
Join us for the first ever CiviCon in San Francisco this April! CiviCon brings (more...)
Extending contact demographic information with a custom group
- Not Just a Contact Database
-
These optional components give you more power to connect and engage your supporters.

civiCONTRIBUTE
Online fundraising and donor management.

civiEVENT
Online event registration and participant tracking.

civiMEMBER
Online signup and membership management.

civiMAIL
Personalized email blasts and newsletters.

civiREPORT
Report generation and template management.
We are working with PTP and Dharmatech to incorporate their work on Canvass and Phonebank into CiviCRM v3.1. Initially we plan to package and release this as the civicrm_canvass drupal module
As part of this work, we need to "extend" the core demographic information in a seamless manner. CiviCRM holds the gender / birth date / deceased date as core fields. However PTP also wanted to collect additional demographic information: ethnicity, primary language, secondary language and number of kids. We plan on storing this additinal demographic data as a custom group. We had to inject this custom group into the demographic section for the contact view and edit forms. We also wanted to hide the custom group showing up as a tabbed pane in the contact view screen.
We accomplished all this using the all powerful and mighty hook system. We could inject a complete custom group into the edit field by implementing the buildForm hook and using some internal CiviCRM functions
// grab the set of custom fields and their type from the DB
// ensure that you have the demographic custom group ID set
$groupTree =& CRM_Core_BAO_CustomGroup::getTree( 'Contact',
$form,
$form->getVar( 'id' ),
CIVICRM_CANVASS_DEMOGRAPHICS_ID,
null, null );
// we should use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree( $groupTree, 1, $form );
// if there are fields to process
if ( isset($groupTree) && is_array($groupTree) ) {
$defaults = array( );
CRM_Core_BAO_CustomGroup::setDefaults( $groupTree, $defaults);
$form->setDefaults( $defaults );
// lets build all the form elements with one nice function call
CRM_Core_BAO_CustomGroup::buildQuickForm( $form, $groupTree, false, 1,
CIVICRM_CANVASS_DEMOGRAPHICS_PREFIX );
}
We also need to modify the templates to inject these custom fields at the right place. I had to restructure the contact edit template so that the demographics had their own separate tpl. This makes it much easier to override just the demographics tpl. I added the following lines of code to the restructured tpl towards the end of the file:
{foreach from=$demographics_groupTree item=cd_edit key=group_id}
{foreach from=$cd_edit.fields item=element key=field_id}

The changes for contact page view were along similar lines. You can check the svn repository for the specific view related changes.

To hide the custom tab from showing up in the contact view screen, we implemented the hook_civicrm_tabs as follows:
function civicrm_canvass_civicrm_tabs( &$tabs, $contactID ) {
foreach ( $tabs as $tabID => $tabValue ) {
if ( $tabValue['title'] == CIVICRM_CANVASS_DEMOGRAPHICS_TITLE ) {
unset( $tabs[$tabID] );
}
}
}
Due to some core civicrm changes, this code will only work in 3.1 and later. I also did not add the custom fields to the advanced search form.







Comments
multi-language and multietnics?
What will be about people speakin mro of a language?
(My girlfriedn is speaking 5 laguages, and who know about future?)
And about people born from the mix of an India and an European and he live around the world, which will be him etnicity?
Custom fields are configurable
All the fields in the screenshot above - OTHER THAN Gender, Date of Birth and Is Deceased - are defined in the Demographics custom data group. This means you can add, remove or change things like language(s), ethnicity, etc. to meet your needs.