[development] Creating "dependent fields" in CCK

Rob Thorne rob at torenware.com
Sat Feb 3 06:47:40 UTC 2007

Nedjo raised a question today concerning CiviNode's CCK widgets.  
civicrmdata.module implements a widget type that is a lot like 
nodereference and userreference, except it points to a contact record in 
CiviCRM,  a PHP contact relation management package.

Right now,  it's possible to select an existing contact (via its 
"contact_id" field), and choose what CiviCRM calls a "profile".  This is 
different than Drupal's profile;  it represents a sort of window into a 
contact by selecting which fields of the contact record you want 
displayed.  Currently,  civicrmdata uses the CiviCRM profile to theme 
and render how the the "contact" displays when a CCK node renders its 

Nedjo wants  tighter integration;  he wants to display and be able to 
edit a single field of a contact record.  This makes a lot of sense, but 
it isn't clear how best to implement this with CCK's hooks.  Here are 
some of the issues;

    * Typically, you want a group of CCK fields that are all related to
      the same CiviCRM contact object,   say as example to indicate "who
      to contact" as part of a CCK node.  If you change the person you
      want to contact, you need all of the dependent fields to point to
      that new CiviCRM contact.  It would be very helpful if the
      contact_id could be changed in one and only one place, and have
      the CCK fields that point to the fields of the contact change in
      lock-step.   Is this how calculated fields (in the contributed
      module) work, and is this the right model?
    * CiviCRM contact records have a fairly large memory footprint,  and
      calling the CiviCRM APIs for fetching contacts takes processor
      time, so ideally, you want to fetch a contact object at most once
      per node (less if you cache between nodes).  Is it possible to
      cache this information at the node level to allow the first field
      to render do the fetch, and all other fields pull from the cache.
    * When a contact field is edited,  order matters;  you don't want to
      write to the CiviCRM data store until all of a contact's
      'dependent fields' have reported their changes.  So it sounds like
      an update needs to happen in two phases.  Can this be done with
      CCK (and Drupal's) current hooks,and if so, which ones do I need
      to look at.

I wrote a good piece of civicrmdata's code, so I'm at least a bit 
familiar with CCK's hooks. But the above issues stump me.  Can anyone 
shed light on this problem?


Rob Thorne
Torenware Networks

More information about the development mailing list