function cck_table_field_formatter_view in CCK Table Field 7
Same name and namespace in other branches
- 8 cck_table.module \cck_table_field_formatter_view()
Implements of hook_field_formatter_view().
File
- ./
cck_table.module, line 90 - Defines a field type that outputs data in a table.
Code
function cck_table_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
$formatter = $display['type'];
switch ($formatter) {
case 'first_row_header':
$header_type = TRUE;
break;
case 'without_header':
$header_type = FALSE;
break;
}
foreach ($items as $delta => $item) {
if (!empty($item['table'])) {
$header = array();
$rows = array();
$lines = explode("\n", $item['table']);
$lines = array_map('trim', $lines);
$lines = array_filter($lines, 'strlen');
foreach ($lines as $line) {
$cells = explode($instance['widget']['settings']['separator'], $line);
if (empty($header) && count($lines) > 1 && $header_type) {
$header = $cells;
}
else {
$rows[] = $cells;
}
}
if (count($rows) > 0) {
$attributes = array();
if (!empty($field['css_id'])) {
$attributes['id'] = $instance['widget']['settings']['css_id'] . '-' . $instanc['id'];
}
if (!empty($field['css_class'])) {
$attributes['class'] = $instance['widget']['settings']['css_class'];
}
}
$element[$delta] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => $attributes,
);
}
}
return $element;
}