--- 1 Fri Nov 07 18:08:09 2008 +++ 2 Mon Oct 13 14:05:10 2008 @@ -6,11 +6,11 @@ */ function textcommaformatter_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')), + 'text_comma' => array( + 'label' => t('Comma-separated'), + 'field types' => array('text'), + 'multiple values' => CONTENT_HANDLE_MODULE, + ), ); } @@ -19,11 +19,9 @@ function textcommaformatter_field_format */ function textcommaformatter_theme() { return array( - 'textcommaformatter_formatter_text_comma' => array('arguments' => array('element' => NULL), 'function' => 'theme_textcommaformatter_formatter_text_comma'), - 'textcommaformatter_formatter_text_comma_and' => array('arguments' => array('element' => NULL), 'function' => 'theme_textcommaformatter_formatter_text_comma'), - 'textcommaformatter_formatter_text_comma_and_period' => array('arguments' => array('element' => NULL), 'function' => 'theme_textcommaformatter_formatter_text_comma'), - 'textcommaformatter_formatter_text_unordered_list' => array('arguments' => array('element' => NULL), 'function' => 'theme_textcommaformatter_formatter_text_comma'), - 'textcommaformatter_formatter_text_ordered_list' => array('arguments' => array('element' => NULL), 'function' => 'theme_textcommaformatter_formatter_text_comma'), + 'textcommaformatter_formatter_text_comma' => array( + 'arguments' => array('element' => NULL), + ), ); } @@ -45,54 +43,5 @@ function theme_textcommaformatter_format $values[] = ($allowed =_text_allowed_values($item)) ? $allowed : $item['#item']['safe']; } - switch ($element['#formatter']) { - case 'text_comma': - $output = implode(', ', $values); - break; - case 'text_comma_and': - $output = ImplodeToEnglish($values, ', ', ''); - break; - case 'text_comma_and_period': - $output = ImplodeToEnglish($values, ', ', '.'); - break; - case 'text_unordered_list': - $output = ImplodeToList($values, 'ul'); - break; - case 'text_ordered_list': - $output = ImplodeToList($values, 'ol'); - break; - } - - return $output; -} - - - - -//taken from http://us.php.net/manual/en/function.implode.php#86845 -function ImplodeToEnglish ($array, $seperator, $suffix) { - // sanity check - if (!$array || !count ($array)) { - return ''; - } - - // get last element - $last = array_pop ($array); - - // if it was the only element - return it - if (!count ($array)) { - return $last; - } - - //return x, x, x and x. - return implode ($seperator, $array) . t(' and ') . $last . $suffix; -} - -function ImplodeToList ($array, $type) { - // sanity check - if (!$array || !count ($array)) { - return ''; - } - - return '<'.$type.'>'."\n".'
  • ' . implode ('
  • '."\n".'
  • ', $array) . '
  • '."\n".''; + return implode(', ', $values); } \ No newline at end of file