summaryrefslogtreecommitdiff
path: root/modules/file
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-01 01:32:59 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-01 01:32:59 +0000
commit6d2573e2013655c57ff995e52cd7f267fa4a3a7f (patch)
treeb5ca4d89fdda154d72ba6c145836bf08db9b1adf /modules/file
parentfb6b16d172f81a5ade06422b4a16717d0939b41d (diff)
downloadbrdo-6d2573e2013655c57ff995e52cd7f267fa4a3a7f.tar.gz
brdo-6d2573e2013655c57ff995e52cd7f267fa4a3a7f.tar.bz2
#913846 by Bevan, grendzy, bleen18, rfay, et al: Fixed Image/file field breaks after uploading two files.
Diffstat (limited to 'modules/file')
-rw-r--r--modules/file/file.field.inc1
-rw-r--r--modules/file/file.module8
-rw-r--r--modules/file/tests/file.test15
3 files changed, 19 insertions, 5 deletions
diff --git a/modules/file/file.field.inc b/modules/file/file.field.inc
index 085bfdc8f..286e2e0b7 100644
--- a/modules/file/file.field.inc
+++ b/modules/file/file.field.inc
@@ -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,
diff --git a/modules/file/file.module b/modules/file/file.module
index 5d76b6c82..0d7453992 100644
--- a/modules/file/file.module
+++ b/modules/file/file.module
@@ -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,
diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test
index b650e605c..ff20a3abc 100644
--- a/modules/file/tests/file.test
+++ b/modules/file/tests/file.test
@@ -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'));