1 file.field.inc | file_field_widget_process_multiple($element, &$form_state, $form) |
Render API callback: Processes a group of file_generic field elements.
Adds the weight field to each row so it can be ordered and adds a new Ajax wrapper around the entire group so it can be replaced all at once.
This function is assigned as a #process callback in file_field_widget_form().
File
- core/
modules/ file/ file.field.inc, line 884 - Field module functionality for the File module.
Code
function file_field_widget_process_multiple($element, &$form_state, $form) {
$element_children = element_children($element, TRUE);
$count = count($element_children);
foreach ($element_children as $delta => $key) {
if ($key != $element['#file_upload_delta']) {
$description = _file_field_get_description_from_element($element[$key]);
$element[$key]['_weight'] = array(
'#type' => 'weight',
'#title' => $description ? t('Weight for @title', array('@title' => $description)) : t('Weight for new file'),
'#title_display' => 'invisible',
'#delta' => $count,
'#default_value' => $delta,
);
}
else {
// The title needs to be assigned to the upload field so that validation
// errors include the correct widget label.
$element[$key]['#title'] = $element['#title'];
$element[$key]['_weight'] = array(
'#type' => 'hidden',
'#default_value' => $delta,
);
}
}
// Add a new wrapper around all the elements for Ajax replacement.
$element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
$element['#suffix'] = '</div>';
return $element;
}