views:

12

answers:

0

In Drupal 6, I have created a simple Pricing CCK compound field module with a "cost" and a "product" sub-field based on this excellent tutorial: http://www.poplarware.com/articles/cck_field_module

function usginpricing_field_settings($op, $field) {
  switch ($op) {
    case 'database columns':
      $columns['cost'] = array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'sortable' => TRUE, 'default' => '', 'views' => TRUE);
      $columns['product'] = array('type' => 'varchar', 'length' => 1000, 'not null' => FALSE, 'sortable' => TRUE, 'default' => '', 'views' => TRUE);
      return $columns;
  }
}

I can retrieve the compound values in Views but how can I pull out the individual sub-fields? So far, I only know where to modify the response (CCK hook_field() implementation - case 'views data':) for Views but am otherwise stumped:

function usginpricing_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    // Do validation on the field values here. The widget
    // will do its own validation and you cannot make any
    // assumptions about what kind of widget has been used,
    // so don't validate widget values, only field values.
    case 'validate':
      if (is_array($items)) {
        foreach ($items as $delta => $item) {
          if ($item['cost'] != '' && !is_numeric(trim($item['cost']))) {
            form_set_error($field['field_name'],t('"%name" is not a valid numeric value',array('%name' => $item['cost'])));
          }
        }
     }
     break;

    case 'sanitize':
      foreach ($items as $delta => $item) {
        foreach ($item as $col => $dat) {
          $items[$delta]['safe_' . $col ] = check_plain($item[ $col ]);
        }
      }
      break;

    // Optional: Make changes to the default $data array
    // created for Views. Omit this if no changes are
    // needed, use it to add a custom handler or make
    // other changes.
    case 'views data':
  // UNFINISHED
      // Start with the $data created by CCK
      // and alter it as needed. The following
      // code illustrates how you would retrieve
      // the necessary data.
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);
      $field_data = $data[$table_alias][$field['field_name'] .'_value'];

      // Make changes to $data as needed here.

      return $data;

  }
}

I'd appreciate any advice or sample code!