What is the bare minimum hooks / cases to setup a custom cck field and widget? What I'm trying to do here is just a simple select list with 2 options. No validations required.

The database is created, the form field shows, however, the values doesn't get saved to db when i submit.
Any help?

function zroy_reference_widget_info() {
  $option_types = array('zroy_reference');
  return array(
    'zroy_options_select' => array(
      'label' => t('Select list'),
      'field types' => $option_types,
    ),
  );
}

function zroy_reference_widget($op, &$node, $field, &$node_field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form[$field['field_name']] = array('#tree' => TRUE);
      
      $form[$field['field_name']]['keys'] = array('#type' => 'select',
                                           '#title' => t($field['widget']['label']),
                                           '#multiple' => TRUE,
                                           '#options' => array('1' => 'a', '2' => 'b'),
                                           );
      return $form;
      break;
  }
}
function zroy_reference_widget_settings($op, $widget) {
  switch($op) {
    case 'form':
      $form = array();
      return $form;
  }
}

function zroy_reference_field_info() {
  return array(
    'zroy_reference' => array('label' => 'zroy_reference'));
}

function zroy_reference_field_settings($op, $field) {
  switch($op) {
    case 'database columns':
        $columns = array(
          'value' => array('type' => 'varchar', 'not null' => TRUE, 'default' => "''", 'sortable' => TRUE),
        );
        if ($field['max_length'] == 0 || $field['max_length'] > 255) {
          $columns['value']['type'] = 'longtext';
        }
        else {
          $columns['value']['length'] = $field['max_length'];
        }
        return $columns;
  }
}

function zroy_reference_field($op, &$node, $field, &$items, $teaser, $page) {

}

Comments

nevets’s picture

I copy over a simple existing widget as a starting point and go from there.

I do have to wonder what the goal is, it seems you can achieve that with CCK's default field types.

resting’s picture

I'm trying to recreate the select list widget. The one cck provides is not able to accept dynamically changed values.
Basically I'm trying to recreate the nodereference thing with AHAH so users don't have to go to views each and everytime to filter the nodes.

Or is there a better solution than this? Pretty clueless how the widget works.

nevets’s picture

Not sure what "users don't have to go to views each and everytime to filter the nodes" means. All users know is they can select a node, the person who sets up the field what determines the set, all nodes, restricted by type or a custom view. What ever the case, the user does not control the list. Can you explain in more detail what you are after?

resting’s picture

Ok, I'll try to be clear.

The nodereference list shown, when creating a new content, is a filtered list using views.

However, this list has to be changed frequently.
To the client, having to go in views to change the filter is a hassle.

Therefore, I need to create my own filters, that changes the list asynchronously, in the content creation form.

Have looked around, don't think there's a module that does this, well...at least not in d5.

nevets’s picture

You have not said how the list changes or how long it is, but you might want to look at the node queue module. With node queue you could create a list of nodes that can referenced, the user can add/delete nodes from the queue and the view can use the queue.