function file_field_widget_submit in Drupal 7
Form submission handler for upload/remove button of file_field_widget_form().
This runs in addition to and after file_managed_file_submit().
See also
1 string reference to 'file_field_widget_submit'
- file_field_widget_process in modules/
file/ file.field.inc - An element #process callback for the file_generic field type.
File
- modules/
file/ file.field.inc, line 761 - Field module functionality for the File module.
Code
function file_field_widget_submit($form, &$form_state) {
// During the form rebuild, file_field_widget_form() will create field item
// widget elements using re-indexed deltas, so clear out $form_state['input']
// to avoid a mismatch between old and new deltas. The rebuilt elements will
// have #default_value set appropriately for the current state of the field,
// so nothing is lost in doing this.
$parents = array_slice($form_state['triggering_element']['#parents'], 0, -2);
drupal_array_set_nested_value($form_state['input'], $parents, NULL);
$button = $form_state['triggering_element'];
// Go one level up in the form, to the widgets container.
$element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -1));
$field_name = $element['#field_name'];
$langcode = $element['#language'];
$parents = $element['#field_parents'];
$submitted_values = drupal_array_get_nested_value($form_state['values'], array_slice($button['#parents'], 0, -2));
foreach ($submitted_values as $delta => $submitted_value) {
if (!$submitted_value['fid']) {
unset($submitted_values[$delta]);
}
}
// Re-index deltas after removing empty items.
$submitted_values = array_values($submitted_values);
// Update form_state values.
drupal_array_set_nested_value($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);
$field_state['items'] = $submitted_values;
field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);
}