Skip to content
Snippets Groups Projects
Commit 6d2573e2 authored by Angie Byron's avatar Angie Byron
Browse files

#913846 by Bevan, grendzy, bleen18, rfay, et al: Fixed Image/file field breaks...

#913846 by Bevan, grendzy, bleen18, rfay, et al: Fixed Image/file field breaks after uploading two files.
parent fb6b16d1
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -441,7 +441,6 @@ function file_field_widget_settings_form($field, $instance) {
* Implements hook_field_widget_form().
*/
function file_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$form['#attributes'] = array('enctype' => 'multipart/form-data');
$defaults = array(
'fid' => 0,
......
......@@ -390,7 +390,6 @@ function file_managed_file_process($element, &$form_state, $form) {
'#value' => t('Upload'),
'#validate' => array(),
'#submit' => array('file_managed_file_submit'),
'#limit_validation_errors' => array($element['#parents']),
'#ajax' => $ajax_settings,
'#weight' => -5,
);
......@@ -404,11 +403,16 @@ function file_managed_file_process($element, &$form_state, $form) {
'#value' => t('Remove'),
'#validate' => array(),
'#submit' => array('file_managed_file_submit'),
'#limit_validation_errors' => array($element['#parents']),
'#ajax' => $ajax_settings,
'#weight' => -5,
);
// Limit validation errors to the file field only. The entire field is needed later
// by file_field_widget_form(), so the last element is sliced off the #parents array
// to avoid removing too much from $form_state['values'].
$element['upload_button']['#limit_validation_errors'] = array(array_slice($element['#parents'], 0, -1));
$element['remove_button']['#limit_validation_errors'] = array(array_slice($element['#parents'], 0, -1));
$element['fid'] = array(
'#type' => 'hidden',
'#value' => $fid,
......
......@@ -114,8 +114,8 @@ class FileFieldTestCase extends DrupalWebTestCase {
);
if (is_numeric($nid_or_type)) {
$node = node_load($nid_or_type);
$delta = isset($node->$field_name) ? count($node->$field_name) : 0;
$node = node_load($nid_or_type, NULL, TRUE);
$delta = isset($node->{$field_name}[LANGUAGE_NONE]) ? count($node->{$field_name}[LANGUAGE_NONE]) : 0;
$edit['files[' . $field_name . '_' . LANGUAGE_NONE . '_' . $delta . ']'] = drupal_realpath($file->uri);
$this->drupalPost('node/' . $nid_or_type . '/edit', $edit, t('Save'));
}
......@@ -280,6 +280,17 @@ class FileFieldWidgetTestCase extends FileFieldTestCase {
$this->assertTrue(empty($node->{$field_name}[LANGUAGE_NONE][0]['fid']), t('File was successfully removed from the node.'));
}
// Test partial form submissions using the Upload button on a multivalue field.
field_delete_field($field_name);
$this->createFileField($field_name, $type_name, array('cardinality' => 3));
$this->drupalGet("node/add/$type_name");
for ($delta = 0; $delta < 3; $delta++) {
$edit = array('files[' . $field_name . '_' . LANGUAGE_NONE . '_' . $delta . ']' => drupal_realpath($test_file->uri));
$this->drupalPost(NULL, $edit, t('Upload'));
}
$this->assertNoFieldByXpath('//input[@type="submit"]', t('Upload'), t('After uploading 3 files, the "Upload" button is no longer displayed.'));
// Test private download method.
$edit = array('field[settings][uri_scheme]' => 'private');
$this->drupalPost("admin/structure/types/manage/$type_name/fields/$field_name", $edit, t('Save settings'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment