function tablefield_rationalize_table in TableField 7
Same name and namespace in other branches
- 6 tablefield.module \tablefield_rationalize_table()
Helper function to turn form elements into a structured array.
Parameters
array $tablefield: The table as it appears in FAPI.
3 calls to tablefield_rationalize_table()
- tablefield_field_formatter_view in ./
tablefield.module - Implements hook_field_formatter_view().
- tablefield_field_load in ./
tablefield.module - Implements hook_field_load().
- tablefield_field_widget_form in ./
tablefield.module - Implements hook_widget_form().
File
- ./
tablefield.module, line 597 - 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_rationalize_table($tablefield) {
$tabledata = array();
// Remove exterraneous form data
$count_cols = $tablefield['rebuild']['count_cols'];
$count_rows = $tablefield['rebuild']['count_rows'];
unset($tablefield['rebuild']);
unset($tablefield['import']);
// Rationalize the table data
if (!empty($tablefield)) {
foreach ($tablefield as $key => $value) {
preg_match('/cell_(.*)_(.*)/', $key, $cell);
// $cell[1] is row count $cell[2] is col count
if ((int) $cell[1] < $count_rows && $cell['2'] < $count_cols) {
$tabledata[$cell[1]][$cell[2]] = $value;
}
}
}
return $tabledata;
}