Hi,
um, returning late to this party: I worked out how to enter and save complex CCK data types. As the drupal.org tutorials seem a bit opaque on this I'm posting it here FYI.
Two of the module hooks for defining the CCK fields need to work in tandem:
hook_field_settings('database columns', $field) needs to return an array for setting up the db columns, with keys for all the sub-data elements:
return array( 'descr' => array('type' => 'varchar', ...), 'depth' => array('type' => 'decimal', ...), 'width' => array('type' => 'decimal', ...), 'height' => array('type' => 'decimal', ...), );
hook_widget('form', ... ) needs to return a chunk of form API with fields whose names match the keys in the above:
$form[$field['field_name']][$delta] = array( '#type' => 'fieldset', 'descr' => array(...), 'depth' => array(...), 'width' => array(...), 'height' => array(...), );
CCK creates the database tables for you: I can't work out what prompts it to create a new table and what just makes it save the values to content_type_foo, though.
If you've read this far, then cheers, J-P
Eric Mckenna wrote:
Can you explain a little more. I'm having trouble making out what you are trying to do. Why does adding these fields to your "book" node not work? And what do you mean by a "complex CCK data type"?
By "complex" I mean having structured data within each occurrence of the field. For example, if my books were available in different languages, then that wouldn't be complex because each CCK field would be just a single dropdown:
Available in:
English German Spanish
Each occurrence of the book's format, however, has five bits of data in it: paperback/hardback, weight in ounces and three dimensions in centimetres. So I can't just use one of the out-of-the-box CCK field types and am not quite sure how to build a field type to cope with it.