diff --git a/textformatter.info b/textformatter.info
index f27c76e..1504c9e 100755
--- a/textformatter.info
+++ b/textformatter.info
@@ -1,5 +1,6 @@
-name = Text Formatter
-description = Provides a formatter for CCK text fields to render multi-value fields.
-dependencies[] = text
-package = CCK
-core = 6.x
+name = Field text formatter
+description = "Add a list display formatter for fields."
+package = Fields
+core = 7.x
+
+dependencies[] = field
diff --git a/textformatter.module b/textformatter.module
index 5319c44..49e289d 100755
--- a/textformatter.module
+++ b/textformatter.module
@@ -1,162 +1,248 @@
 <?php
 
 /**
- * Implementation of hook_field_formatter_info().
+ * @file
+ * Provides a field display formatter to render text field content as html lists.
+ *
  */
-function textformatter_field_formatter_info() {
-  return array(
-    'text_comma' => array(
-      'label' => t('Commas'),
-      'multiple values' => CONTENT_HANDLE_MODULE,
-      'field types' => array('text')),
-
-    'text_comma_and' => array(
-      'label' => t('Commas-And'),
-       'multiple values' => CONTENT_HANDLE_MODULE,
-      'field types' => array('text')),
-
-    'text_comma_and_period' => array(
-      'label' => t('Commas-And-Period'),
-      'multiple values' => CONTENT_HANDLE_MODULE,
-      'field types' => array('text')),
-
-    'text_unordered_list' => array(
-      'label' => t('Unordered List'),
-      'multiple values' => CONTENT_HANDLE_MODULE,
-      'field types' => array('text')),
-
-    'text_ordered_list' => array(
-      'label' => t('Ordered List'),
-      'multiple values' => CONTENT_HANDLE_MODULE,
-      'field types' => array('text')),
-  );
-}
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_field_formatter_info().
  */
-function textformatter_theme() {
+function textformatter_field_formatter_info() {
   return array(
-    'textformatter_formatter_text_comma' => array(
-       'arguments' => array('element' => NULL),
-      'function' => 'theme_textformatter_formatter_text_comma'),
-
-    'textformatter_formatter_text_comma_and' => array(
-      'arguments' => array('element' => NULL),
-      'function' => 'theme_textformatter_formatter_text_comma_and'),
-
-    'textformatter_formatter_text_comma_and_period' => array(
-      'arguments' => array('element' => NULL),
-      'function' => 'theme_textformatter_formatter_text_comma_and_period'),
-
-    'textformatter_formatter_text_ordered_list' => array(
-      'arguments' => array('element' => NULL),
-      'function' => 'theme_textformatter_formatter_text_orderedlist'),
-
-    'textformatter_formatter_text_unordered_list' => array(
-      'arguments' => array('element' => NULL),
-      'function' => 'theme_textformatter_formatter_text_unorderedlist'),
+    'textformatter_list' => array(
+      'label' => t("Textformatter list"),
+      'field types' => array('text', 'text_long', 'number_integer', 'number_decimal', 'number_float', 'list_float', 'list_integer', 'list_text'),
+      'settings' => array( // Change this to instance settings instead?
+        'textformatter_type' => 'ul',
+        'textformatter_class' => '',
+        'textformatter_comma_full_stop' => 0,
+        'textformatter_comma_and' => 0,
+        'textformatter_comma_tag' => NULL,
+      ),
+    ),
   );
 }
 
 /**
- * Return an array of the values from a text field element.
+ * Implements hook_field_formatter_Settings_form().
  */
-function textformatter_formatter_get_element_values($element) {
-  // Get data out of multidimensional $element array and place it in flat $values array.
-  $values = array();
-
-  $item = $element;
-  foreach (element_children($element) as $key) {
-    unset($item[$key]);
+function textformatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
+  $display = $instance['display'][$view_mode];
+  $settings = $display['settings'];
+
+  $form = array();
+
+  if ($display['type'] == 'textformatter_list') {
+    $form['textformatter_type'] = array(
+      '#title' => t("List type"),
+      '#type' => 'select',
+      '#options' => array(
+        'ul' => t("Unordered HTML list (ul)"),
+        'ol' => t("Ordered HTML list (ol)"),
+        'comma' => t("Comma separated list"),
+      ),
+      '#default_value' => $settings['textformatter_type'],
+      '#required' => TRUE,
+    );
+    $form['textformatter_comma_and'] = array(
+      '#type' => 'checkbox',
+      '#title' => t("Include 'and' after each comma"),
+      '#default_value' => $settings['textformatter_comma_and'],
+      '#states' => array(
+        'visible' => array(
+          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array('value' => 'comma'),
+        ),
+      ),
+    );
+    $form['textformatter_comma_full_stop'] = array(
+      '#type' => 'checkbox',
+      '#title' => t("Append comma separated list with") . ' \'.\'',
+      '#default_value' => $settings['textformatter_comma_full_stop'],
+      '#states' => array(
+        'visible' => array(
+          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array('value' => 'comma'),
+        ),
+      ),
+    );
+    $form['textformatter_comma_tag'] = array(
+      '#type' => 'select',
+      '#title' => t("HTML wrapper"),
+      '#description' => t("An HTML tag to wrap the list in. The CSS class below will be added to this tag."),
+      '#options' => _textformatter_available_tags(),
+      '#default_value' => $settings['textformatter_comma_tag'],
+      '#states' => array(
+        'visible' => array(
+          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array('value' => 'comma'),
+        ),
+      ),
+    );
+    $form['textformatter_class'] = array(
+      '#title' => t("List classes"),
+      '#type' => 'textfield',
+      '#size' => 40,
+      '#description' => t("The CSS class to use in the markup for the field list. 
+        If this field is left blank it will default to 'textformatter-list'."),
+      '#default_value' => $settings['textformatter_class'],
+      '#required' => FALSE,
+    );
   }
 
-  foreach (element_children($element) as $key) {
-    $item['#item'] = $element[$key]['#item'];
-    $values[] = ($allowed =_text_allowed_values($item)) ? $allowed : $item['#item']['safe'];
-  }
-
-  // Trim values in the array.
-  $values = array_map('trim', $values);
-
-  // Kill empty values in the array.
-  $values = array_filter($values);
-
-
-  return $values;
+  return $form;
 }
 
 /**
- * Theme a textfield as a comma-separated list.
- *
- * @ingroup themeable
+ * Implements hook_field_formatter_settings_summary().
  */
-function theme_textformatter_formatter_text_comma($element) {
-  $values = textformatter_formatter_get_element_values($element);
-  return implode(', ', $values);
+function textformatter_field_formatter_settings_summary($field, $instance, $view_mode) {
+  $display = $instance['display'][$view_mode];
+  $settings = $display['settings'];
+
+  $summary = array();
+
+  if ($display['type'] == 'textformatter_list') {
+    $list_type = $settings['textformatter_type'];
+    switch ($list_type) {
+      case 'ul':
+        $summary[] = t("Unordered HTML list");
+      break;
+      case 'ol':
+        $summary[] = t("Ordered HTML list");
+      break;
+      case 'comma':
+        $summary[] = t("Comma separated list");
+      break;
+    }
+    if ($settings['textformatter_class']) {
+      $summary[] = t("CSS Class") . ': <em>' . check_plain($settings['textformatter_class']) . '</em>';
+    }
+    $summary = theme('item_list', array('type' => 'ul', 'items' => $summary));
+  }
+
+  return $summary;
 }
 
 /**
- * Theme a textfield as a comma-separated list with an "and".
- *
- * @ingroup themeable
+ * Implements hook_field_formatter_view().
  */
-function theme_textformatter_formatter_text_comma_and($element) {
-  $values = textformatter_formatter_get_element_values($element);
-
-  $phrase = "";
-  for ($i = 0; $i < count($values); $i++) {
-    if ($i == (count($values) - 2)) {
-      $phrase .= $values[$i]." and ";
-    }
-    else {
-      $phrase .= $values[$i].", ";
-    }
+function textformatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+  $settings = $display['settings'];
+  $element = array();
+
+  switch ($display['type']) {
+    case 'textformatter_list':
+      $list_type = $settings['textformatter_type'];
+      $list_items = array();
+
+      if ($field['type'] == 'text_long') {
+        foreach ($items as $delta => $item) {
+          // array filter out any empty lines in the exploded array
+          // (trim removes whitespace character, meaning array element will become empty).
+          $long_text_items = array_filter(array_map('trim', explode("\n", $item['value'])));
+          foreach ($long_text_items as $item_key => $long_text_item) {
+            $list_items[] = $long_text_item;
+          }
+        }
+      }
+      else {
+        foreach ($items as $delta => $item) {
+          $list_items[$delta] = check_plain($item['value']);
+        }
+      }
+      // If there are no items, return and render nothing.
+      if (empty($list_items)) {
+        return;
+      }
+      
+      $classes = $settings['textformatter_class'];
+      $classes = isset($classes) ? drupal_html_class($classes) : '';
+      
+      switch ($list_type) {
+        case 'ul':
+        case 'ol':
+          //Render elements as one piece of markup and theme as item list.
+          $element[0] = array(
+            '#theme' => 'item_list',
+            '#type' => $list_type,
+            '#items' => $list_items,
+            '#attributes' => array('class' => $classes),
+          );
+        break;
+        case 'comma':
+          $element[0] = array(
+            '#theme' => 'textformatter_comma',
+            '#items' => $list_items,
+            '#full_stop' => $settings['textformatter_comma_full_stop'],
+            '#comma_and' => $settings['textformatter_comma_and'],
+            '#comma_tag' => $settings['textformatter_comma_tag'],
+            '#attributes' => array('class' => $classes),
+          );
+        break;
+      }
+    break;
   }
 
-  return $phrase;
+  return $element;
 }
 
 /**
- * Theme a textfield as a comma-separated list with an "and" and period.
- *
- * @ingroup themeable
+ * returns keyed array of available html tags.
  */
-function theme_textformatter_formatter_text_comma_and_period($element) {
-  $values = textformatter_formatter_get_element_values($element);
-
-  $phrase = "";
-  for ($i = 0; $i < count($values); $i++) {
-    if ($i == (count($values) - 2)) {
-      $phrase .= $values[$i]." and ";
-    }
-    else if ($i == (count($values) - 1)) {
-      $phrase .= $values[$i];
-    }
-    else {
-      $phrase .= $values[$i].", ";
-    }
-  }
+function _textformatter_available_tags() {
+  $tags = array(
+    'none' => t('No HTML tag'),
+    'span' => t('Span'),
+    'p' => t('Paragraph'),
+    'h1' => t('Header 1'),
+    'h2' => t('Header 2'),
+    'h3' => t('Header 3'),
+    'h4' => t('Header 4'),
+    'h5' => t('Header 5'),
+    'h6' => t('Header 6'),
+  );
 
-  return ($phrase) ? $phrase."." : $phrase;
+  return $tags;
 }
 
 /**
- * Theme a textfield as an HTML ordered list.
- *
- * @ingroup themeable
+ * Implements hook_theme().
  */
-function theme_textformatter_formatter_text_orderedlist($element) {
-  $values = textformatter_formatter_get_element_values($element);
-  return theme('item_list', $values, NULL, 'ol');
+function textformatter_theme($existing, $type, $theme, $path) {
+  return array(
+    'textformatter_comma' => array(
+      'render element' => 'variables',
+    ),
+  );
 }
 
 /**
- * Theme a textfield as an HTML unordered list.
- *
- * @ingroup themeable
+ * Theme function to render comma separated lists.
  */
-function theme_textformatter_formatter_text_unorderedlist($element) {
-  $values = textformatter_formatter_get_element_values($element);
-  return theme('item_list', $values, NULL, 'ul');
+function theme_textformatter_comma($variables) {
+
+  $items = $variables['variables']['#items'];
+  $class = $variables['variables']['#attributes']['class'];
+  $full_stop = $variables['variables']['#full_stop'];
+  $and = $variables['variables']['#comma_and'];
+  $html_tag = $variables['variables']['#comma_tag'] !== 'none' ? $variables['variables']['#comma_tag'] : NULL;
+
+  $output = '';
+  $output = '<' . ($html_tag ? $html_tag : 'div') . ' class="' . ($class ? drupal_html_class($class) : 'textformatter-list') . '">';
+
+  //Add 'and,' or just ',' depending on setting.
+  if ($and) {
+    $output .= implode("," . t("and") . " ", $items);
+  }
+  else {
+    $output .= implode(", ", $items);
+  }
+
+  //Add full stop to output if setting is checked.
+  if ($full_stop) {
+    $output .= '.';
+  }
+  $output .= '</' . $html_tag . '>';
+
+  return $output;
 }
