function tablefield_field_formatter_view in TableField 7
Same name and namespace in other branches
- 7.3 tablefield.module \tablefield_field_formatter_view()
- 7.2 tablefield.module \tablefield_field_formatter_view()
Implements hook_field_formatter_view().
File
- ./
tablefield.module, line 168 - This module provides a set of fields that can be used to store tabular data with a node. The implementation uses a custom CCK widget.
Code
function tablefield_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
$formatter = $display['type'];
foreach ($items as $delta => $table) {
// Rationalize the stored data
if (!empty($table['tablefield'])) {
$tabledata = tablefield_rationalize_table($table['tablefield']);
}
elseif (!empty($table['value'])) {
$tabledata = tablefield_rationalize_table(unserialize($table['value']));
}
// Run the table through input filters
if (isset($tabledata)) {
if (!empty($tabledata)) {
foreach ($tabledata as $row_key => $row) {
foreach ($row as $col_key => $cell) {
if (!empty($table['format'])) {
$tabledata[$row_key][$col_key] = array(
'data' => check_markup($cell, $table['format']),
'class' => array(
'row_' . $row_key,
'col_' . $col_key,
),
);
}
else {
$tabledata[$row_key][$col_key] = array(
'data' => check_plain($cell),
'class' => array(
'row_' . $row_key,
'col_' . $col_key,
),
);
}
}
}
}
// Pull the header for theming
$header = array_shift($tabledata);
// Theme the table for display
$element[$delta]['#markup'] = theme('tablefield_view', array(
'header' => $header,
'rows' => $tabledata,
'delta' => $delta,
));
}
}
return $element;
}