diff --git a/core/modules/field/field.install b/core/modules/field/field.install index dc20e25..24b2950 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -537,4 +537,3 @@ function field_update_8004() { * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ - diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 3ca855e..2327bb3 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -259,32 +259,3 @@ function file_update_8001() { ); db_change_field('file_usage', 'id', 'id', $spec); } - -/** -* Convert image field's default image configuration to the new format. -*/ -function file_update_8002() { - if (module_exists('field_sql_storage')) { - $fields = field_read_fields(array('type' => 'image'), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); - foreach ($fields as $field) { - if (!empty($field['settings']['default_image'])) { - $field['settings']['default_image'] = array($field['settings']['default_image']); - } - else { - $field['settings']['default_image'] = array(); - } - field_update_field($field); - - $instances = field_read_instances(array('field_name' => $field['field_name'])); - foreach ($instances as $instance) { - if (!empty($instance['settings']['default_image'])) { - $instance['settings']['default_image'] = array($instance['settings']['default_image']); - } - else { - $instance['settings']['default_image'] = array(); - } - field_update_instance($instance); - } - } - } -} diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 18dae26..dfccd33 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1135,7 +1135,11 @@ function file_managed_file_submit($form, &$form_state) { $fids = array_diff($fids, $remove_fids); } else { + // If we deal with single upload element remove the file and set + // element's value to empty array (file could not be removed from + // element if we don't do that). $remove_fids = $fids; + $fids = array(); } foreach ($remove_fids as $fid) { diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index a287620..eed43df 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' => file_default_scheme(), - 'default_image' => array(), + 'default_image' => 0, 'column_groups' => array( 'file' => array( 'label' => t('File'), @@ -44,7 +44,7 @@ function image_field_info() { 'title_field_required' => 0, 'max_resolution' => '', 'min_resolution' => '', - 'default_image' => array(), + 'default_image' => 0, ), 'default_widget' => 'image_image', 'default_formatter' => 'image', @@ -79,7 +79,7 @@ function image_field_settings_form($field, $instance) { '#title' => t('Default image'), '#type' => 'managed_file', '#description' => t('If no image is uploaded, this image will be shown on display.'), - '#default_value' => $field['settings']['default_image'], + '#default_value' => empty($field['settings']['default_image']) ? array() : array($field['settings']['default_image']), '#upload_location' => $settings['uri_scheme'] . '://default_images/', ); @@ -197,7 +197,7 @@ function image_field_instance_settings_form($field, $instance) { '#title' => t('Default image'), '#type' => 'managed_file', '#description' => t("If no image is uploaded, this image will be shown on display and will override the field's default image."), - '#default_value' => $settings['default_image'], + '#default_value' => empty($settings['default_image']) ? array() : array($settings['default_image']), '#upload_location' => $field['settings']['uri_scheme'] . '://default_images/', ); @@ -234,11 +234,11 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $ $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']; + $fid = array($instances[$id]['settings']['default_image']); } // Otherwise, use the default for the field. elseif (!empty($field['settings']['default_image'])) { - $fid = $field['settings']['default_image']; + $fid = array($field['settings']['default_image']); } // Add the default image if one is found. diff --git a/core/modules/image/image.module b/core/modules/image/image.module index a7696a6..0483c03 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -1030,3 +1030,26 @@ function image_filter_keyword($value, $current_pixels, $new_pixels) { function _image_effect_definitions_sort($a, $b) { return strcasecmp($a['name'], $b['name']); } + +/** + * Implements hook_entity_presave(). + * + * Transforms default image of image field from array into single value at save. + */ +function image_entity_presave(Drupal\Core\Entity\EntityInterface $entity, $type) { + $field = FALSE; + if ($type == 'field_instance') { + $field = $entity->field; + } + if ($type == 'field_entity') { + $field = $entity; + } + if ($field && $field->type == 'image') { + if (!empty($entity->settings['default_image'][0])) { + $entity->settings['default_image'] = $entity->settings['default_image'][0]; + } + else { + $entity->settings['default_image'] = 0; + } + } +} diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 4f22958..bb01a8f 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -732,7 +732,7 @@ function user_update_8011() { 'title_field' => 0, 'max_resolution' => update_variable_get('user_picture_dimensions', '85x85'), 'min_resolution' => '', - 'default_image' => !empty($default_image_fid) ? $default_image_fid : 0, + 'default_image' => !empty($default_image_fid) ? array($default_image_fid) : array(), ), ); _update_7000_field_create_instance($field, $instance);