problems saving/loading value of checkbox widget

Events happening in the community are now at Drupal community events on www.drupal.org.
mariuss's picture

I created a custom cck field that shows links to mapping sites. It can be used with content types that have a physical address. The widget is just a checkbox, that tells if mapping links should be shown or not for this particular node.

I am definitely doing something wrong because the value of this checkbox is not saved or loaded properly from the database.

I also asked for help on the main drupal forum:
http://drupal.org/node/150266

The module is See Map:
http://drupal.org/project/see_map

And here is the widget code:

<?php
// hook_widget_info
function see_map_widget_info() {
  return array(
   
'see_map_checkbox' => array(
     
'label' => '"See Map" links',
     
'field types' => array('see_map'),
    ),
  );
}

// hook_widget_settings
function see_map_widget_settings($op, $widget) {
  switch (
$op) {
    case
'validate':
      if (
$widget['required'] == 1) {
       
form_set_error('required', t('See Map field cannot be required!'));
      }
      if (
$widget['multiple'] == 1) {
       
form_set_error('multiple', t('See Map field cannot have multiple values!'));
      }
      break;
  }
}

// hook_widget
function see_map_widget($op, &$node, $field, &$items) {
  switch (
$op) {
    case
'form':
     
$form = array();
     
     
$default_value = 0;
      if (isset(
$field['widget']['default_value'][0]['show_see_map'])) {
         
$default_value = $field['widget']['default_value'][0]['show_see_map'];
      }
     
     
$form[$field['field_name']][0]['show_see_map'] = array(
       
'#type' => 'checkbox',
       
'#title' => t('Show "!seemap" links.', array('!seemap' => $field['widget']['label'])),
       
'#default_value' => isset($items[0]['show_see_map']) ? $items[0]['show_see_map'] : $default_value,
       
'#required' => FALSE,
       
'#description' => $field['widget']['description'],
      );
     
      return
$form;
  }
}
?>

Any suggestions or pointers to relevant documentation or similar modules are more than appreciated.

Thanks,
Marius

Comments

#tree property