function theme_community_tags_settings in Community Tags 6
Same name and namespace in other branches
- 6.2 community_tags.admin.inc \theme_community_tags_settings()
- 7 community_tags.admin.inc \theme_community_tags_settings()
Theme function for presets form element - display in table.
File
- ./
community_tags.admin.inc, line 196 - community_tags.admin.inc
Code
function theme_community_tags_settings($form) {
$rows = array();
$elements = element_children($form['community_tags_settings']);
// $first = $form[reset($form)];
$notes = array();
$header_rows = array();
$rows = array();
$first_row = TRUE;
$first_type_row = TRUE;
$vocab_index = 0;
$type_column_count = 1;
foreach ($elements as $key) {
// content types enabled for this vocabulary - may not be any
$type_elements = element_children($form['community_tags_settings'][$key]['types']);
$content_type_count = count($type_elements);
$rowspan = $content_type_count == 0 ? 1 : $content_type_count;
// First column 'vocabulary' - if first pass rocess header - get description if any
$row_data = array();
$row_data[] = array(
'data' => $form['community_tags_settings'][$key]['#title'],
'rowspan' => $rowspan,
);
if ($first_row) {
$header_rows[0][] = array(
'data' => t('Vocabulary'),
);
if ($form['community_tags_settings'][$key]['#description']) {
$notes[] = $form['community_tags_settings'][$key]['#description'];
}
}
// Vocabulary level columns - if first pass process header - get descriptions if any
$vocab_elements = element_children($form['community_tags_settings'][$key]);
foreach ($vocab_elements as $vocab_key) {
if ($vocab_key != 'types') {
if ($first_row) {
$header_rows[0][] = array(
'data' => $form['community_tags_settings'][$key][$vocab_key]['#title'],
);
if ($form['community_tags_settings'][$key][$vocab_key]['#description']) {
$notes[] = $form['community_tags_settings'][$key][$vocab_key]['#description'];
}
}
unset($form['community_tags_settings'][$key][$vocab_key]['#description']);
unset($form['community_tags_settings'][$key][$vocab_key]['#title']);
$row_data[] = array(
'data' => drupal_render($form['community_tags_settings'][$key][$vocab_key]),
'rowspan' => $rowspan,
);
}
}
// stripe per vocabulary
$row_class = $vocab_index % 2 == 0 ? 'odd' : 'even';
if ($content_type_count > 0) {
// get first and move pointer on
$first_type = TRUE;
foreach ($type_elements as $type_key) {
$type_element = $form['community_tags_settings'][$key]['types'][$type_key];
$type_sub_elements = element_children($form['community_tags_settings'][$key]['types'][$type_key]);
// content type link cell
$row_data['type'] = array(
'data' => $type_element['#title'],
);
if ($first_type_row) {
$type_column_count = count($type_sub_elements) + 1;
// need type headings - increase rowspan of vocab headings
foreach ($header_rows[0] as $header_index => $header_cell) {
$header_rows[0][$header_index]['rowspan'] = 2;
}
// previous data rows may need expanding
foreach ($rows as $row_key => $row) {
$rows[$row_key]['data']['type']['colspan'] = $type_column_count;
}
// types heading - will have nested type-specific headings
$header_rows[0]['type'] = array(
'data' => $form['community_tags_settings'][$key]['types']['#title'],
'colspan' => $type_column_count,
);
// start second header row
$header_rows[1][] = array(
'data' => t('Type'),
);
if ($type_element['#description']) {
$notes[] = $type_element['#description'];
}
}
foreach ($type_sub_elements as $sub_element_key) {
if ($first_type_row) {
$header_rows[1][] = array(
'data' => $type_element[$sub_element_key]['#title'],
);
if ($type_element[$sub_element_key]['#description']) {
$notes[] = $type_element[$sub_element_key]['#description'];
}
}
unset($type_element[$sub_element_key]['#description']);
unset($type_element[$sub_element_key]['#title']);
$row_data[] = array(
'data' => drupal_render($type_element[$sub_element_key]),
);
}
$rows[] = array(
'data' => $row_data,
'class' => $row_class,
);
// reset row data - don't need it row subsequent content type rows
$row_data = array();
$first_type_row = FALSE;
}
}
else {
// No types assigned
$row_data['type'] = array(
'data' => t('No assigned content types.'),
'colspan' => $type_column_count,
);
if ($first_row) {
// types heading - first row - don't know that we have type settings yet
$header_rows[0]['type'] = array(
'data' => $form['community_tags_settings'][$key]['types']['#title'],
);
}
$rows[] = array(
'data' => $row_data,
'class' => $row_class,
);
}
$vocab_index += 1;
$first_row = FALSE;
}
$output = '<div class="form-item"><label>' . $form['community_tags_settings']['#title'] . ':</label>';
// output the table - don't use standard theme because want bespoke striping
$xoutput .= '<table><thead>';
foreach ($header_rows as $header_row) {
$xoutput .= '<tr>';
foreach ($header_row as $header_cell) {
$xoutput .= _theme_table_cell($header_cell, TRUE);
}
$xoutput .= '</tr>';
}
$xoutput .= '</thead><tbody>';
foreach ($rows as $row) {
$xoutput .= '<tr class="' . $row['class'] . '">';
foreach ($row['data'] as $data_cell) {
$xoutput .= _theme_table_cell($data_cell);
}
$xoutput .= '</tr>';
}
$xoutput .= '</tbody></table>';
$output .= $xoutput;
// add notes pulled from form elements to the end of the table
if (!empty($notes)) {
$output .= theme('item_list', $notes, NULL, 'ul', array(
'class' => 'description',
));
}
// end of form-item div.
$output .= '</div>';
// clear all this
drupal_render($form['community_tags_settings']);
$output .= drupal_render($form);
return $output;
}