function theme_cck_table_formatter in CCK Table Field 6
Implementation of hook_field_formatter().
1 string reference to 'theme_cck_table_formatter'
- cck_table_theme in ./
cck_table.module - Implementation of hook_theme().
File
- ./
cck_table.module, line 126 - Defines a field type that outputs data in a table.
Code
function theme_cck_table_formatter($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
$value = $element['#item']['value'];
switch ($element['#formatter']) {
case 'first_row_header':
$header_type = TRUE;
break;
case 'without_header':
$header_type = FALSE;
break;
}
if (!empty($value)) {
$header = array();
$rows = array();
$lines = explode("\n", $value);
$lines = array_map('trim', $lines);
$lines = array_filter($lines, 'strlen');
foreach ($lines as $line) {
$cells = explode($field['separator'], $line);
if (count($header) == 0 && count($lines) > 1 && $header_type) {
$header = $cells;
}
else {
$rows[] = $cells;
}
}
if (count($rows) > 0) {
$attributes = array();
if (!empty($field['css_id'])) {
$attributes['id'] = $field['css_id'] . '-' . $element['#node']->nid;
}
if (!empty($field['css_class'])) {
$attributes['class'] = $field['css_class'];
}
return theme('table', $header, $rows, $attributes);
}
}
}