theme_file_widget_multiple
- Versions
- 7
theme_file_widget_multiple($variables)
Theme a group of file upload widgets.
Code
modules/file/file.field.inc, line 712
<?php
function theme_file_widget_multiple($variables) {
$element = $variables['element'];
$field = field_info_field($element['#field_name']);
$instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
// Get our list of widgets in order.
$widgets = array();
foreach (element_children($element) as $key) {
$widgets[$key] = $element[$key];
}
usort($widgets, '_field_sort_items_value_helper');
// Special ID and classes for draggable tables.
$weight_class = $element['#id'] . '-weight';
$table_id = $element['#id'] . '-table';
// Build up a table of applicable fields.
$headers = array();
$headers[] = t('File information');
if (!empty($field['settings']['display_field'])) {
$headers[] = array(
'data' => t('Display'),
'class' => array('checkbox'),
);
}
$headers[] = t('Weight');
$headers[] = t('Operations');
$rows = array();
foreach ($widgets as $key => $widget) {
// Save the uploading row for last.
if ($element[$key]['#file'] == FALSE) {
$element[$key]['#title'] = $element['#file_upload_title'];
$element[$key]['#description'] = $element['#file_upload_description'];
continue;
}
// Render all the buttons in the field as an "operation".
$operations = '';
foreach (element_children($element[$key]) as $sub_key) {
if (isset($element[$key][$sub_key]['#type']) && $element[$key][$sub_key]['#type'] == 'submit') {
$operations .= drupal_render($element[$key][$sub_key]);
}
}
// Render the "Display" option in its own own column.
$display = '';
if (!empty($field['settings']['display_field'])) {
unset($element[$key]['display']['#title']);
$display = array(
'data' => drupal_render($element[$key]['display']),
'class' => array('checkbox'),
);
}
// Render the weight in its own column.
$element[$key]['_weight']['#attributes']['class'] = array($weight_class);
$weight = drupal_render($element[$key]['_weight']);
// Render everything else together in a column, without the normal wrappers.
$element[$key]['#theme_wrappers'] = array();
$information = drupal_render($element[$key]);
$row = array();
$row[] = $information;
if (!empty($field['settings']['display_field'])) {
$row[] = $display;
}
$row[] = $weight;
$row[] = $operations;
$rows[] = array(
'data' => $row,
'class' => isset($element[$key]['#attributes']['class']) ? array_merge($element[$key]['#attributes']['class'], array('draggable')) : array('draggable'),
);
}
drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class);
$output = '';
$output = empty($rows) ? '' : theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id)));
$output .= drupal_render_children($element);
return $output;
}
?>Login or register to post comments 