--- \cck_formatters\textcommaformatter\textcommaformatter.module Mon Oct 13 15:05:10 2008 +++ \cck_formatters\textformatter\textformatter.module Fri Jan 2 00:47:46 2009 @@ -1,27 +1,62 @@ array( - 'label' => t('Comma-separated'), - 'field types' => array('text'), + '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(). */ -function textcommaformatter_theme() { +function textformatter_theme() { return array( - 'textcommaformatter_formatter_text_comma' => array( + 'textformatter_formatter_text_comma' => array( 'arguments' => array('element' => NULL), - ), + 'function' => 'theme_textformatter_formatter_text'), + + 'textformatter_formatter_text_comma_and' => array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_textformatter_formatter_text'), + + 'textformatter_formatter_text_comma_and_period' => array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_textformatter_formatter_text'), + + 'textformatter_formatter_text_unordered_list' => array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_textformatter_formatter_text'), + + 'textformatter_formatter_text_ordered_list' => array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_textformatter_formatter_text'), ); } @@ -30,7 +65,8 @@ * * @ingroup themeable */ -function theme_textcommaformatter_formatter_text_comma($element) { +function theme_textformatter_formatter_text($element) { + //get data out of multidimensional $element array and place it in flat $values array $values = array(); $item = $element; @@ -43,5 +79,37 @@ $values[] = ($allowed =_text_allowed_values($item)) ? $allowed : $item['#item']['safe']; } - return implode(', ', $values); -} + //kill empty values in the array + foreach ($values as $key => $value) { + if (is_null($value) || $value=="") { + unset($values[$key]); + } + } + //$values array ready for use + + + //format output + switch ($element['#formatter']) { + case 'text_comma': + $output = implode(', ', $values); + break; + + case 'text_comma_and': + $output = cckformatterfunctions_ImplodeToEnglish($values, ', ', ''); + break; + + case 'text_comma_and_period': + $output = cckformatterfunctions_ImplodeToEnglish($values, ', ', '.'); + break; + + case 'text_unordered_list': + $output = cckformatterfunctions_ImplodeToList($values, 'ul'); + break; + + case 'text_ordered_list': + $output = cckformatterfunctions_ImplodeToList($values, 'ol'); + break; + } + + return $output; +} \ No newline at end of file