View source
<?php
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',
),
),
);
}
function textformatter_theme() {
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',
),
);
}
function textformatter_formatter_get_element_values($element) {
$values = array();
$item = $element;
foreach (element_children($element) as $key) {
unset($item[$key]);
}
foreach (element_children($element) as $key) {
$item['#item'] = $element[$key]['#item'];
$values[] = ($allowed = _text_allowed_values($item)) ? $allowed : $item['#item']['safe'];
}
$values = array_map('trim', $values);
$values = array_filter($values);
return $values;
}
function theme_textformatter_formatter_text_comma($element) {
$values = textformatter_formatter_get_element_values($element);
return implode(', ', $values);
}
function theme_textformatter_formatter_text_comma_and($element) {
$values = textformatter_formatter_get_element_values($element);
$last = '';
if (count($values) > 1) {
$last = array_pop($values);
$last = ' ' . t('and') . ' ' . $last;
}
$phrase = implode(', ', $values) . $last;
return $phrase;
}
function theme_textformatter_formatter_text_comma_and_period($element) {
$phrase = theme_textformatter_formatter_text_comma_and($element);
if ($phrase) {
return $phrase . '.';
}
return NULL;
}
function theme_textformatter_formatter_text_orderedlist($element) {
$values = textformatter_formatter_get_element_values($element);
if (!empty($values)) {
return theme('item_list', $values, NULL, 'ul');
}
return NULL;
}
function theme_textformatter_formatter_text_unorderedlist($element) {
$values = textformatter_formatter_get_element_values($element);
if (!empty($values)) {
return theme('item_list', $values, NULL, 'ul');
}
return NULL;
}