diff --git a/core/includes/file.inc b/core/includes/file.inc index dc98bf7..a0c2840 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1025,7 +1025,7 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { /** * Saves file uploads to a new location. * - * The files will be added to the {file_managed} table as temporary files. + * The files will be added to the {file_managed} table as temporary files. * Temporary files are periodically cleaned. Use file_usage()->add() to register * the usage of the file which will automatically mark it as permanent. * @@ -1044,9 +1044,8 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { * A string containing the URI $source should be copied to. * This must be a stream wrapper URI. If this value is omitted, Drupal's * temporary files scheme will be used ("temporary://"). - * @param $position - * Delta of a file of only one file needs to be saved. All files - * will be saved if set to FALSE (default). + * @param $delta + * Delta of the file to save or NULL to save all files. Defaults to NULL. * @param $replace * Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE: Replace the existing file. @@ -1055,8 +1054,8 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { * - FILE_EXISTS_ERROR: Do nothing and return FALSE. * * @return - * Function returns array of files or a single file object if $position - * != FALSE. Each file object contains the file information if the + * Function returns array of files or a single file object if $delta + * != NULL. Each file object contains the file information if the * upload succeeded or FALSE in the event of an error. Function * returns NULL if no file was uploaded. * @@ -1067,18 +1066,18 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { * - source: Path to the file before it is moved. * - destination: Path to the file after it is moved (same as 'uri'). */ -function file_save_upload($source, $validators = array(), $destination = FALSE, $position = FALSE, $replace = FILE_EXISTS_RENAME) { +function file_save_upload($source, $validators = array(), $destination = FALSE, $delta = NULL, $replace = FILE_EXISTS_RENAME) { global $user; static $upload_cache; // Return cached objects without processing since the file will have // already been processed and the paths in $_FILES will be invalid. if (isset($upload_cache[$source])) { - if ($position === FALSE) { - return $upload_cache[$source]; + if (isset($delta)) { + return $upload_cache[$source][$delta]; } else { - return $upload_cache[$source][$position]; + return $upload_cache[$source]; } } @@ -1088,34 +1087,34 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, } $files = array(); - foreach ($_FILES['files']['name'][$source] as $delta => $name) { + foreach ($_FILES['files']['name'][$source] as $i => $name) { // Check for file upload errors and return FALSE for this file if a lower // level system error occurred. For a complete list of errors: // See http://php.net/manual/features.file-upload.errors.php. - switch ($_FILES['files']['error'][$source][$delta]) { + switch ($_FILES['files']['error'][$source][$i]) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $name, '%maxsize' => format_size(file_upload_max_size()))), 'error'); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_FILE: drupal_set_message(t('The file %file could not be saved because the upload did not complete.', array('%file' => $name)), 'error'); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; case UPLOAD_ERR_OK: // Final check that this is a valid upload, if it isn't, use the // default error handler. - if (is_uploaded_file($_FILES['files']['tmp_name'][$source][$delta])) { + if (is_uploaded_file($_FILES['files']['tmp_name'][$source][$i])) { break; } // Unknown error default: drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $name)), 'error'); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; } @@ -1124,8 +1123,8 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, 'uid' => $user->uid, 'status' => 0, 'filename' => trim(drupal_basename($name, '.')), - 'uri' => $_FILES['files']['tmp_name'][$source][$delta], - 'filesize' => $_FILES['files']['size'][$source][$delta], + 'uri' => $_FILES['files']['tmp_name'][$source][$i], + 'filesize' => $_FILES['files']['size'][$source][$i], ); $values['filemime'] = file_get_mimetype($values['filename']); $file = entity_create('file', $values); @@ -1182,7 +1181,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, $destination_scheme = file_uri_scheme($destination); if (!file_stream_wrapper_valid_scheme($destination_scheme)) { drupal_set_message(t('The file could not be uploaded because the destination %destination is invalid.', array('%destination' => $destination)), 'error'); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; } @@ -1196,7 +1195,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, // there's an existing file so we need to bail. if ($file->destination === FALSE) { drupal_set_message(t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', array('%source' => $source, '%directory' => $destination)), 'error'); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; } @@ -1216,7 +1215,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, $message .= ' ' . array_pop($errors); } form_set_error($source, $message); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; } @@ -1224,10 +1223,10 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, // directory. This overcomes open_basedir restrictions for future file // operations. $file->uri = $file->destination; - if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source][$delta], $file->uri)) { + if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source][$i], $file->uri)) { form_set_error($source, t('File upload error. Could not move uploaded file.')); watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri)); - $files[$delta] = FALSE; + $files[$i] = FALSE; continue; } @@ -1245,13 +1244,13 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, // If we made it this far it's safe to record this file in the database. $file->save(); - $files[$delta] = $file; + $files[$i] = $file; } // Add files to the cache. $upload_cache[$source] = $files; - return $position === FALSE ? $files : $files[$position]; + return isset($delta) ? $files[$delta] : $files; } /** diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 6981752..e1bf021 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1040,7 +1040,7 @@ function($item) { } } - // Load files if the FIDs has changed to confirm they exist. + // Load files if the FIDs have changed to confirm they exist. if (!empty($input['fids'])) { $fids = array(); foreach ($input['fids'] as $key => $fid) { @@ -1114,7 +1114,7 @@ function file_managed_file_validate(&$element, &$form_state) { form_error($element['upload'], t('!name field is required.', array('!name' => $element['#title']))); } - // Save entire values to storage + // Save entire values to storage. $values = NestedArray::getValue($form_state['values'], $element['#array_parents']); if (!isset($form_state['storage']['managed_file_values'])) { $form_state['storage']['managed_file_values'] = array(); @@ -1225,13 +1225,10 @@ function file_managed_file_save_upload($element) { } // Value callback expects FIDs to be keys. - $uploads = array(); $files = array_filter($files); - foreach ($files as $file) { - $uploads[$file->fid] = $file; - } + $fids = array_map(function($file) {return $file->fid;}, $files); - return $uploads; + return array_combine($fids, $files); } return array(); diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 9842ad6..23ae208 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -187,16 +187,16 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $element['#weight'] = $delta; - // If we just loaded from DB we have to translate value to - // multivalue file widgets. + // If we just loaded from DB we have to translate value to multivalue file + // widgets. if (!isset($items[$delta]['fids']) && isset($items[$delta]['fid'])) { $items[$delta]['fids'][0] = $items[$delta]['fid']; } $element['#default_value'] = !empty($items[$delta]) ? $items[$delta] : $defaults; - if (empty($element['#default_value']['fids'])) { + if (empty($element['#default_value'])) { $element['#description'] = theme('file_upload_help', array('description' => $element['#description'], 'upload_validators' => $element['#upload_validators'])); - $element['#multiple'] = $this->field['cardinality'] != 0 ? TRUE : FALSE; + $element['#multiple'] = $this->field['cardinality'] ? FALSE : TRUE; if ($this->field['cardinality'] != 1 && $this->field['cardinality'] != -1) { $element['#element_validate'] = array('file_field_widget_multiple_count_validate'); } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 52df6f2..6defa77 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -147,7 +147,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, } // Attach a file to the node. - $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($file->uri); + $edit['files[' . $field_name . '_' . $langcode . '_0][]'] = drupal_realpath($file->uri); $this->drupalPost("node/$nid/edit", $edit, t('Save and keep published')); return $nid; @@ -172,7 +172,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { */ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { $edit = array( - 'files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0]' => drupal_realpath($file->uri), + 'files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0][]' => drupal_realpath($file->uri), 'revision' => (string) (int) $new_revision, ); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 28a5d5d..ae72138 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -113,7 +113,7 @@ function testMultiValuedWidget() { $this->drupalGet("node/add/$type_name"); foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = array('files[' . $each_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . ']' => drupal_realpath($test_file->uri)); + $edit = array('files[' . $each_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . '][]' => drupal_realpath($test_file->uri)); // If the Upload button doesn't exist, drupalPost() will automatically // fail with an assertion message. $this->drupalPost(NULL, $edit, t('Upload')); @@ -272,7 +272,7 @@ function testPrivateFileComment() { // Add a comment with a file. $text_file = $this->getTestFile('text'); $edit = array( - 'files[field_' . $name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->uri), + 'files[field_' . $name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . 0 . '][]' => drupal_realpath($text_file->uri), 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $comment_body = $this->randomName(), ); $this->drupalPost(NULL, $edit, t('Save')); diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module index 5ec0428..8cff297 100644 --- a/core/modules/file/tests/file_test/file_test.module +++ b/core/modules/file/tests/file_test/file_test.module @@ -126,7 +126,7 @@ function _file_test_form_submit(&$form, &$form_state) { $validators['file_validate_extensions'] = array($form_state['values']['extensions']); } - $file = file_save_upload('file_test_upload', 0, $validators, $destination, 0, $form_state['values']['file_test_replace']); + $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state['values']['file_test_replace']); if ($file) { $form_state['values']['file_test_upload'] = $file; drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri))); diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index e83d542..f3c2d73 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -18,7 +18,7 @@ function image_field_info() { 'description' => t('This field stores the ID of an image file as an integer value.'), 'settings' => array( 'uri_scheme' => variable_get('file_default_scheme', 'public'), - 'default_image' => 0, + 'default_image' => array(), ), 'instance_settings' => array( 'file_extensions' => 'png gif jpg jpeg', @@ -30,7 +30,7 @@ function image_field_info() { 'title_field_required' => 0, 'max_resolution' => '', 'min_resolution' => '', - 'default_image' => 0, + 'default_image' => array(), ), 'default_widget' => 'image_image', 'default_formatter' => 'image', @@ -216,7 +216,7 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $ // If there are no files specified at all, use the default. foreach ($entities as $id => $entity) { if (empty($items[$id])) { - $fid = 0; + $fid = array(); // Use the default for the instance if one is available. if (!empty($instances[$id]['settings']['default_image'])) { $fid = $instances[$id]['settings']['default_image']; @@ -227,7 +227,7 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $ } // Add the default image if one is found. - if ($fid && ($file = file_load($fid))) { + if ($fid && ($file = file_load($fid[0]))) { $items[$id][0] = (array) $file + array( 'is_default' => TRUE, 'alt' => '', @@ -298,16 +298,17 @@ function image_field_is_empty($item, $field) { */ function image_field_widget_process($element, &$form_state, $form) { $item = $element['#value']; - $item['fid'] = $element['fid']['#value']; + $item['fids'] = $element['fids']['#value']; $element['#theme'] = 'image_widget'; $element['#attached']['css'][] = drupal_get_path('module', 'image') . '/image.theme.css'; // Add the image preview. - if ($element['#file'] && $element['#preview_image_style']) { + if (!empty($element['#files']) && $element['#preview_image_style']) { + $file = reset($element['#files']); $variables = array( 'style_name' => $element['#preview_image_style'], - 'uri' => $element['#file']->uri, + 'uri' => $file->uri, ); // Determine image dimensions. @@ -316,7 +317,7 @@ function image_field_widget_process($element, &$form_state, $form) { $variables['height'] = $element['#value']['height']; } else { - $info = image_get_info($element['#file']->uri); + $info = image_get_info($file->uri); if (is_array($info)) { $variables['width'] = $info['width']; @@ -357,7 +358,7 @@ function image_field_widget_process($element, &$form_state, $form) { // @see http://www.gawds.org/show.php?contentid=28 '#maxlength' => 512, '#weight' => -2, - '#access' => (bool) $item['fid'] && $element['#alt_field'], + '#access' => (bool) $item['fids'] && $element['#alt_field'], '#element_validate' => $settings['alt_field_required'] == 1 ? array('_image_field_required_fields_validate') : array(), ); $element['title'] = array( @@ -367,7 +368,7 @@ function image_field_widget_process($element, &$form_state, $form) { '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'), '#maxlength' => 1024, '#weight' => -1, - '#access' => (bool) $item['fid'] && $element['#title_field'], + '#access' => (bool) $item['fids'] && $element['#title_field'], '#element_validate' => $settings['alt_field_required'] == 1 ? array('_image_field_required_fields_validate') : array(), ); @@ -422,8 +423,9 @@ function theme_image_widget($variables) { } $output .= '
'; diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 956eafd..b0cece6 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -402,8 +402,8 @@ function image_field_delete_field($field) { } // The value of a managed_file element can be an array if #extended == TRUE. - $fid = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); - if ($fid && ($file = file_load($fid))) { + $fid = (isset($field['settings']['default_image']['fids']) ? $field['settings']['default_image']['fids'] : $field['settings']['default_image']); + if ($fid && ($file = file_load($fid[0]))) { file_usage()->delete($file, 'image', 'default_image', $field['id']); } } @@ -417,10 +417,10 @@ function image_field_update_field($field, $prior_field, $has_data) { } // The value of a managed_file element can be an array if #extended == TRUE. - $fid_new = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); - $fid_old = (is_array($prior_field['settings']['default_image']) ? $prior_field['settings']['default_image']['fid'] : $prior_field['settings']['default_image']); + $fid_new = (isset($field['settings']['default_image']['fids']) ? $field['settings']['default_image']['fids'] : $field['settings']['default_image']); + $fid_old = (isset($prior_field['settings']['default_image']['fids']) ? $prior_field['settings']['default_image']['fids'] : $prior_field['settings']['default_image']); - $file_new = $fid_new ? file_load($fid_new) : FALSE; + $file_new = $fid_new ? file_load($fid_new[0]) : FALSE; if ($fid_new != $fid_old) { @@ -432,7 +432,7 @@ function image_field_update_field($field, $prior_field, $has_data) { } // Is there an old file? - if ($fid_old && ($file_old = file_load($fid_old))) { + if ($fid_old && ($file_old = file_load($fid_old[0]))) { file_usage()->delete($file_old, 'image', 'default_image', $field['id']); } } @@ -481,13 +481,15 @@ function image_field_update_instance($instance, $prior_instance) { // The value of a managed_file element can be an array if the #extended // property is set to TRUE. $fid_new = $instance['settings']['default_image']; - if (is_array($fid_new)) { - $fid_new = $fid_new['fid']; + if (isset($fid_new['fids'])) { + $fid_new = $fid_new['fids']; } + $fid_new = $fid_new[0]; $fid_old = $prior_instance['settings']['default_image']; - if (is_array($fid_old)) { - $fid_old = $fid_old['fid']; + if (isset($fid_old['fids'])) { + $fid_old = $fid_old['fids']; } + $fid_old = $fid_old[0]; // If the old and new files do not match, update the default accordingly. $file_new = $fid_new ? file_load($fid_new) : FALSE; @@ -1063,4 +1065,3 @@ function image_filter_keyword($value, $current_pixels, $new_pixels) { function _image_effect_definitions_sort($a, $b) { return strcasecmp($a['name'], $b['name']); } - diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php index 35cb3fa..6ba4353 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php @@ -61,7 +61,7 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ if ($this->field['cardinality'] == 1) { // If there's only one field, return it as delta 0. - if (empty($elements[0]['#default_value']['fid'])) { + if (empty($elements[0]['#default_value']['fids'])) { $elements[0]['#description'] = theme('file_upload_help', array('description' => $this->instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); } } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index 01fa5f4..a30b7ed 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -43,10 +43,10 @@ function testDefaultImages() { // Create an image field and add an instance to the article content type. $field_name = strtolower($this->randomName()); $field_settings = array( - 'default_image' => $default_images['field']->fid, + 'default_image' => array($default_images['field']->fid), ); $instance_settings = array( - 'default_image' => $default_images['instance']->fid, + 'default_image' => array($default_images['instance']->fid), ); $widget_settings = array( 'preview_image_style' => 'medium', @@ -63,7 +63,7 @@ function testDefaultImages() { 'label' => $instance['label'], 'required' => $instance['required'], 'settings' => array( - 'default_image' => $default_images['instance2']->fid, + 'default_image' => array($default_images['instance2']->fid), ), 'widget' => $instance['widget'], ); @@ -76,7 +76,7 @@ function testDefaultImages() { // Confirm the defaults are present on the article field settings form. $this->drupalGet("admin/structure/types/manage/article/fields/$field_name/field-settings"); $this->assertFieldByXpath( - '//input[@name="field[settings][default_image][fid]"]', + '//input[@name="field[settings][default_image][fids]"]', $default_images['field']->fid, format_string( 'Article image field default equals expected file ID of @fid.', @@ -86,7 +86,7 @@ function testDefaultImages() { // Confirm the defaults are present on the article field edit form. $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); $this->assertFieldByXpath( - '//input[@name="instance[settings][default_image][fid]"]', + '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance']->fid, format_string( 'Article image field instance default equals expected file ID of @fid.', @@ -97,7 +97,7 @@ function testDefaultImages() { // Confirm the defaults are present on the page field settings form. $this->drupalGet("admin/structure/types/manage/page/fields/$field_name/field-settings"); $this->assertFieldByXpath( - '//input[@name="field[settings][default_image][fid]"]', + '//input[@name="field[settings][default_image][fids]"]', $default_images['field']->fid, format_string( 'Page image field default equals expected file ID of @fid.', @@ -107,7 +107,7 @@ function testDefaultImages() { // Confirm the defaults are present on the page field edit form. $this->drupalGet("admin/structure/types/manage/page/fields/$field_name"); $this->assertFieldByXpath( - '//input[@name="instance[settings][default_image][fid]"]', + '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance2']->fid, format_string( 'Page image field instance default equals expected file ID of @fid.', @@ -140,13 +140,13 @@ function testDefaultImages() { ); // Upload a new default for the field. - $field['settings']['default_image'] = $default_images['field_new']->fid; + $field['settings']['default_image'] = array($default_images['field_new']->fid); field_update_field($field); // Confirm that the new default is used on the article field settings form. $this->drupalGet("admin/structure/types/manage/article/fields/$field_name/field-settings"); $this->assertFieldByXpath( - '//input[@name="field[settings][default_image][fid]"]', + '//input[@name="field[settings][default_image][fids]"]', $default_images['field_new']->fid, format_string( 'Updated image field default equals expected file ID of @fid.', @@ -175,14 +175,14 @@ function testDefaultImages() { ); // Upload a new default for the article's field instance. - $instance['settings']['default_image'] = $default_images['instance_new']->fid; + $instance['settings']['default_image'] = array($default_images['instance_new']->fid); field_update_instance($instance); // Confirm the new field instance default is used on the article field // admin form. $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); $this->assertFieldByXpath( - '//input[@name="instance[settings][default_image][fid]"]', + '//input[@name="instance[settings][default_image][fids]"]', $default_images['instance_new']->fid, format_string( 'Updated article image field instance default equals expected file ID of @fid.', @@ -220,7 +220,7 @@ function testDefaultImages() { // Confirm the article field instance default has been removed. $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); $this->assertFieldByXpath( - '//input[@name="instance[settings][default_image][fid]"]', + '//input[@name="instance[settings][default_image][fids]"]', '', 'Updated article image field instance default has been successfully removed.' ); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 7c42a5b..743237a 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -227,13 +227,13 @@ function testImageFieldDefaultImage() { // Add a default image to the public imagefield instance. $images = $this->drupalGetTestFiles('image'); $edit = array( - 'files[field_settings_default_image]' => drupal_realpath($images[0]->uri), + 'files[field_settings_default_image][]' => drupal_realpath($images[0]->uri), ); $this->drupalPost("admin/structure/types/manage/article/fields/$field_name/field-settings", $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field($field_name); - $image = file_load($field['settings']['default_image']); + $image = file_load($field['settings']['default_image'][0]); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); $default_output = theme('image', array('uri' => $image->uri)); $this->drupalGet('node/' . $node->nid); @@ -255,7 +255,7 @@ function testImageFieldDefaultImage() { // Remove default image from the field and make sure it is no longer used. $edit = array( - 'field[settings][default_image][fid]' => 0, + 'field[settings][default_image][fids]' => 0, ); $this->drupalPost("admin/structure/types/manage/article/fields/$field_name/field-settings", $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. @@ -268,14 +268,14 @@ function testImageFieldDefaultImage() { $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private')); // Add a default image to the new field. $edit = array( - 'files[field_settings_default_image]' => drupal_realpath($images[1]->uri), + 'files[field_settings_default_image][]' => drupal_realpath($images[1]->uri), ); $this->drupalPost('admin/structure/types/manage/article/fields/' . $private_field_name . '/field-settings', $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. field_info_cache_clear(); $private_field = field_info_field($private_field_name); - $image = file_load($private_field['settings']['default_image']); + $image = file_load($private_field['settings']['default_image'][0]); $this->assertEqual('private', file_uri_scheme($image->uri), 'Default image uses private:// scheme.'); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); // Create a new node with no image attached and ensure that default private diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index 5a4e20e..e8518ab 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -117,7 +117,7 @@ function uploadNodeImage($image, $field_name, $type) { $edit = array( 'title' => $this->randomName(), ); - $edit['files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0][]'] = drupal_realpath($image->uri); $this->drupalPost('node/add/' . $type, $edit, t('Save and publish')); // Retrieve ID of the newly created node from the current URL.