function theme_fapi_table in Subform 5
Format a group of form items.
Parameters
$element: An associative array containing the properties of the element. Properties used: attributes, title, value, description, children, collapsible, collapsed
Return value
A themed HTML string representing the form item group.
File
- ./
fapi_table.module, line 26
Code
function theme_fapi_table($table_element) {
$types_lookup = array(
'boolean' => 'alphanumeric',
'integer' => 'numeric',
'double' => 'numeric',
'string' => 'alphanumeric',
'array' => 'alphanumeric',
'object' => 'alphanumeric',
'resource' => 'alphanumeric',
'NULL' => 'alphanumeric',
);
drupal_add_js(drupal_get_path('module', 'subform') . '/table.js');
$table_contents = '';
foreach ($table_element['rows'] as $row_id => $row) {
$header = $table_element['#header'] && $row_id == 0;
if (is_string($row_id) && substr($row_id, 0, 1) == '#') {
continue;
}
if ($header) {
$table_contents .= '<thead><tr>';
}
else {
$table_contents .= "<tr class=" . ($row_id % 2 ? "'even'" : "'odd'") . ">";
}
foreach ($row as $cell_id => $cell) {
if (is_string($cell_id) && substr($cell_id, 0, 1) == "#") {
continue;
}
if ($header) {
$classes = '';
if ($cell['#table-sortable']) {
$classes .= ' table-sortable:' . $types_lookup[$cell['#table-sortable']];
}
if ($cell['#table-filterable']) {
$classes .= ' table-filterable';
}
$table_contents .= "<th class=\"{$classes}\">";
}
else {
$table_contents .= '<td>';
}
if (isset($cell['#children'])) {
$table_contents .= $cell['#children'];
}
if ($header) {
$table_contents .= "</th>";
}
else {
$table_contents .= "</td>";
}
}
if ($header) {
$table_contents .= "</tr></thead>";
}
else {
$table_contents .= "</tr>";
}
}
if (!isset($table_element['#attributes']['border']) && isset($table_element['#border'])) {
$table_element['#attributes']['border'] = $table_element['#border'];
}
if (!isset($table_element['#attributes']['width']) && isset($table_element['#width'])) {
$table_element['#attributes']['width'] = $table_element['#width'];
}
if (!isset($table_element['#attributes']['height']) && isset($table_element['#height'])) {
$table_element['#attributes']['height'] = $table_element['#height'];
}
$table_element['#attributes']['class'] .= " table-autosort table-autofilter";
// $table_element['#attributes']['class'] .= "table-autosort";
$attributes = drupal_attributes($table_element['#attributes']);
return "<table {$attributes} >{$table_contents}</table>\n";
}