function mfw_field_widget_process_multiple in Multiupload Filefield Widget 7
An element #process callback for a group of mfw_file fields.
Mostly copied from drupal core module /module/file/file.field.inc.
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.
1 string reference to 'mfw_field_widget_process_multiple'
File
- ./
multiupload_filefield_widget.field.inc, line 177 - Field module functionality for the Multiple File Widget module.
Code
function mfw_field_widget_process_multiple($element, &$form_state, $form) {
$upload_name = implode('_', $element['#parents']) . '_' . $element['#file_upload_delta'];
if (isset($_FILES['files']['name']) && array_key_exists($upload_name, $_FILES['files']['name'])) {
$count = count($_FILES['files']['name'][$upload_name]);
// Supposing #file_upload_delta is always the last delta this will work
for ($i = 1; $i < $count; $i++) {
$element[] = $element[$element['#file_upload_delta']];
}
}
$element_children = element_children($element);
$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;
}