Custom field type with imagefield I'm creating a widget with an image field. But I keep writing 0 to the database. But i need the fid to be saved. I know I can manipulate the data with hook_field_presave(). But the items array only contains image => '0'.

mymodule.module

/**
* Implements hook_field_widget_form().
*/
function mymodule_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
...
  $element['image'] = array(
    '#type' =&gt; 'managed_file',
    '#name' =&gt; 'mymodule_custom_image',
    '#title' =&gt; t('Image'),
    '#size' =&gt; 40,
    '#description' =&gt; t(""),
    '#upload_location' =&gt; 'public://',
    '#theme' =&gt; 'mymodule_custom_thumb_upload',
  ); 
...
}


Edit:

/**
* Implements hook_field_widget_info().
*/
function mymodule_field_widget_info() {
  return array(
    'mymodule_polygone_widget' =&gt; array(
      'label' =&gt; t('Default'),
      'field types' =&gt; array('mymodule_polygone'),
    ),
  );
}


mymodule.install

/*
* Implements hook_field_schema().
*/
function mymodule_field_schema($field) {
  $columns = array(
    'image' =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; TRUE),
    'zones' =&gt; array('type' =&gt; 'text'),
  );

  return array(
    'columns' =&gt; $columns,
    'indexes' =&gt; array(),
  );
}
Found it: Forgot the 'input ...' in my custom theme function :).

function theme_mymodule_thumb_upload($variables) {
  $element = $variables['element'];

  if (isset($element['#file']-&gt;uri)) {
      $output = '&lt;div id="edit-logo-ajax-wrapper"&gt;&lt;div class="form-item form-type-managed-file form-item-logo"&gt;&lt;span class="file"&gt;';
      $output .= '&lt;img src="' . file_create_url($element['#file']-&gt;uri) . '" /&gt;';
      $output .= '&lt;/span&gt;&lt;input type="submit" id="edit-' . $element['#name'] . '-remove-button" name="' . $element['#name'] . '_remove_button" value="Remove" class="form-submit ajax-processed"&gt;';
      $output .= '&lt;input type="hidden" name="' . $element['#name'] . '[fid]" value="' . $element['#file']-&gt;fid . '"&gt;';

      return $output;
  }
}