function theme_matrix_table in Matrix field 8.2
Same name and namespace in other branches
- 6.2 matrix.module \theme_matrix_table()
- 7.2 matrix.module \theme_matrix_table()
Theme a set of form elements into a table
File
- ./
matrix.module, line 532 - Contains matrix.module.
Code
function theme_matrix_table($variables) {
$form = $variables['form'];
$rows_count = $form['#matrix_rows'];
$cols_count = $form['#matrix_cols'];
$more_cols = $form['#matrix_more_cols'];
$more_rows = $form['#matrix_more_rows'];
$column_labels = $form['#column_labels'];
$row_labels = $form['#row_labels'];
$field_name = $form['#field_name'];
$table_rows = array();
for ($row = 1; $row <= $rows_count; $row++) {
for ($col = 1; $col <= $cols_count; $col++) {
$table_rows[$row - 1][$col - 1] = drupal_render($form['grid'][$row . '-' . $col]);
}
}
//lables
if (!empty($row_labels)) {
array_unshift($column_labels, '');
//The first column will contain the label
foreach ($row_labels as $id => $label) {
array_unshift($table_rows[$id - 1], $label);
}
}
//if there should be a "more rows" button, render a new row with just the button
if ($more_rows) {
$table_rows[$rows_count][1] = drupal_render($form['more_rows']);
for ($col = 2; $col <= $cols_count; $col++) {
$table_rows[$rows_count][$col] = ' ';
}
}
//if there should be a "more columns" button, render a new column with just the button
if ($more_cols) {
$column_labels[] = drupal_render($form['more_cols']);
for ($row = 1; $row <= $rows_count; $row++) {
$table_rows[$row - 1][$cols_count + 1] = ' ';
}
}
$output = '<div id="matrix-field-' . $field_name . '">';
$output .= _theme('form_element_label', array(
'element' => $form,
));
$output .= _theme('table', array(
'header' => $column_labels,
'rows' => $table_rows,
));
$output .= filter_xss_admin($form['#description']);
$output .= '</div>';
return $output;
}