How to pass formatter settings to field theme function? I've created a field by implementing hook_field_info, I've created the widget which works perfectly and I've hit a road block with the formatter.

I've implemented hook_field_formatter_settings_form to add some extra output options but I can't work out how to get those values passed to the theme function when the field is rendered.

Here is a simpified version of my code, it's not all the hooks just the ones related to the formatter and the field's theme:

function test_field_formatter_info() {
    return array(
        'test' =&gt; array(
            'label' =&gt; t('Test'),
            'field types' =&gt; array('test'),
        ),
    );
}

function test_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  foreach ($items as $delta =&gt; $item) {

    $element[$delta] = array(
      '#theme' =&gt; 'test',
      '#item' =&gt; $item,
      '#myextravalue' =&gt; $display['settings']['myextravalue'],
    );
  }

  return $element;  
}

function test_theme() {
  return array(
    'test' =&gt; array (
      'variables' =&gt; array('item' =&gt; NULL, 'myextravalue' =&gt; NULL),
    ),
  );
}

function theme_test($variables) {   
    $item = $variables['item'];
    ...
    return $output;
}


The widget, field and formatter are working fine, I just can't work out how to get the formatter settings that were defined by hook_field_formatter_settings_form to the test theme function.

When I $variables variable I only see an array for item. myextravalue is not there!

There is very little information on how to create fields/widgets/formatters for Drupal 7 and I'm pulling my hair out with this.
Your formatter_view implementation looks ok, very similar to image_field_formatter_view().

However, you're info hook seems to be missing default values for your settings, I'm not sure if they are required or not, but try to add them, again see image_field_formatter_info()

Does the field_formatter_settings form work correctly? Does it show correctly in the summary and keeps the values when you edit it again?

Without more information, the only advice I can give you is install devel.module if you haven't already and make extensive use of dpm() to see where you get which information. For example, contains $display the necessary information in your formatter_view() function?

If yes, it could simply be a outdated theme registry that does not yet know about your additional theme argument (if you added later on for example).