diff -u b/core/modules/file/file.field.inc b/core/modules/file/file.field.inc --- b/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -403,7 +403,7 @@ * This validator is used only when cardinality not set to 1 or unlimited. */ function file_field_widget_multiple_count_validate($element, &$form_state, $form) { - $parents = $element['#array_parents']; + $parents = $element['#parents']; $values = NestedArray::getValue($form_state['values'], $parents); array_pop($parents); @@ -433,7 +433,7 @@ 'warning' ); $values['fids'] = array_slice($values['fids'], 0, $keep); - NestedArray::setValue($form_state['values'], $element['#array_parents'], $values); + NestedArray::setValue($form_state['values'], $element['#parents'], $values); } } @@ -601,7 +601,7 @@ $langcode = $element['#language']; $parents = $element['#field_parents']; - $submitted_values = NestedArray::getValue($form_state['values'], array_slice($button['#array_parents'], 0, -2)); + $submitted_values = NestedArray::getValue($form_state['values'], array_slice($button['#parents'], 0, -2)); foreach ($submitted_values as $delta => $submitted_value) { if (empty($submitted_value['fids'])) { unset($submitted_values[$delta]); @@ -612,10 +612,15 @@ // them, as we display each file in it's own widget. $new_values = array(); foreach ($submitted_values as $delta => $submitted_value) { - foreach ($submitted_value['fids'] as $fid) { + if (is_array($submitted_value['fids'])) { + foreach ($submitted_value['fids'] as $fid) { + $new_value = $submitted_value; + $new_value['fids'] = array($fid); + $new_values[] = $new_value; + } + } + else { $new_value = $submitted_value; - $new_value['fids'] = array($fid); - $new_values[] = $new_value; } } @@ -623,7 +628,7 @@ $submitted_values = array_values($new_values); // Update form_state values. - NestedArray::setValue($form_state['values'], array_slice($button['#array_parents'], 0, -2), $submitted_values); + NestedArray::setValue($form_state['values'], array_slice($button['#parents'], 0, -2), $submitted_values); // Update items. $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); diff -u b/core/modules/file/file.module b/core/modules/file/file.module --- b/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1008,8 +1008,6 @@ * This function is assigned as a #value_callback in file_element_info(). */ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) { - $fids = array(); - // Find the current value of this field. $fids = !empty($input['fids']) ? explode(' ', $input['fids']) : array(); foreach ($fids as $key => $fid) { @@ -1185,8 +1183,8 @@ * The FAPI element whose values are being saved. * * @return - * The file entity representing the file that was saved, or FALSE if no file - * was saved. + * An array of file entities for each file that was saved, keyed by its file + * ID, or FALSE if no files were saved. */ function file_managed_file_save_upload($element) { $upload_name = implode('_', $element['#parents']);