Index: composite_cck.module
===================================================================
--- composite_cck.module	(revision 320)
+++ composite_cck.module	(working copy)
@@ -17,10 +17,10 @@
 /***********************************************************
 *                          FIELDS                          *
 ************************************************************/
-  
+
 function composite_cck_composite_field_field_api(&$reference, $op, $node = NULL, $a4 = NULL) {
   if (strpos($reference['id'], '-')) {
-    // This is a field value, dispatch it. 
+    // This is a field value, dispatch it.
     return composite_cck_composite_field_value_api($reference, $op, $node, $a4);
   }
 
@@ -39,20 +39,22 @@
 
       // We're going to be naughty here and poke our display settings in.
       // Unfortunately, we can't do this for the label - content_preprocess_content_field()
-      //    re-fetches the label display setting from content.module. 
+      //    re-fetches the label display setting from content.module.
       $field['display_settings']['full']['format'] = $reference['data']['format'];
 
       $data = content_field('view', $node, $field, $node->$field_id, FALSE, FALSE);
       drupal_alter('composite_data', $data);
       return drupal_render($data);
       break;
-      
+
     // Return form elements for additional settings
-    case 'settings':      
+    case 'settings':
+      $current_field = $reference['id'];
+      $current_field_values = $node->$current_field;
       $form['format'] = array(
         '#title' => t('Display as'),
         '#type' => 'select',
-        '#options' => _composite_cck_formatter_options($reference['id']),
+        '#options' => _composite_cck_formatter_options($reference['id'], $current_field_values),
         '#default_value' => $reference['data']['format'],
       );
       return $form;
@@ -82,7 +84,7 @@
       }
     }
   }
-  
+
   return $options;
 }
 
@@ -92,7 +94,7 @@
 
 function composite_cck_composite_field_value_api(&$reference, $op, $node = NULL, $a4 = NULL) {
   switch ($op) {
-    // Derive additional fields 
+    // Derive additional fields
     case 'load':
       list($reference['parent_field'], $reference['delta']) = explode('-', $reference['id'], 2);
       break;
@@ -117,18 +119,20 @@
       // Extract out the field value
       $field_items = $node->$field_id;
       if ($field_items[$reference['delta']]) {
-        $field_item = array(0 => $field_items[$reference['delta']]);        
+        $field_item = array(0 => $field_items[$reference['delta']]);
         $field['display_settings']['full']['format'] = $reference['data']['format'];
         $data = content_field('view', $node, $field, $field_item, FALSE, FALSE);
         return drupal_render($data);
       }
       break;
-      
+
     case 'settings':
+      $current_field = $reference['parent_field'];
+      $current_field_values = $node->$current_field;
       $form['format'] = array(
         '#title' => t('Display as'),
         '#type' => 'select',
-        '#options' => _composite_cck_formatter_options($reference['parent_field']),
+        '#options' => _composite_cck_formatter_options($reference['parent_field'], $current_field_values[$reference['delta']]),
         '#default_value' => $reference['data']['format'],
       );
       return $form;
@@ -141,22 +145,32 @@
 *                     HELPER FUNCTIONS                     *
 ************************************************************/
 
-// Retrieve a select list of formatter options for a field
-function _composite_cck_formatter_options($field_id) {
+/**
+ * Retrieve a select list of formatter options for a field
+ * @param field_id The id of the field we want to fetch the formatters for
+ * @param field_value The value(s) of the field (in an array) we want to check the formatter suitability callback against
+ */
+function _composite_cck_formatter_options($field_id, $field_value = NULL) {
   $field = content_fields($field_id);
-
   $field_types = _content_field_types();
   $field_type = $field_types[$field['type']];
-  
+
   // Construct a formatters select list
   $formatter_options = array();
   if (is_array($field_type['formatters'])) {
     foreach ($field_type['formatters'] as $formatter_name => $formatter_info) {
+      // If it is a multiple value formatter
+      if (content_handle('formatter', 'multiple values', $formatter_info) != CONTENT_HANDLE_CORE) {
+        continue;
+      }
+      // If the formatter provide a suitability callback, use it with the value
+      if (is_array($field_value) && $formatter_info["suitability callback"] != "" && $formatter_info["suitability callback"]($field_value, $formatter_info["suitability callback arguments"]) == FALSE) {
+        continue;
+      }
       $formatter_options[$formatter_name] = $formatter_info['label'];
     }
     $formatter_options['hidden'] = t('<Hidden>');
   }
-  
   return $formatter_options;
 }
 
@@ -198,4 +212,4 @@
       return l($data->name, "user/$data->uid");
     }
   }
-}
+}
\ No newline at end of file
