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.install b/core/modules/image/image.install index ea20840..573fb3f 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -188,48 +188,3 @@ function image_update_8002() { 'image_style_preview_image' => 'preview_image', )); } - - -/** - * Convert image field's default image configuration to the new format. - */ -function image_update_8003() { - foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) { - $field_config = config($config_name); - if ($field_config->get('type') == 'image') { - $settings = $field_config->get('settings'); - - // Some update hooks (like user_update_8011()) create image fields with - // the 'default_image' setting directly in the correct format. We do not - // need to update those. - if (!is_array($settings['default_image'])) { - if (!empty($settings['default_image'])) { - $settings['default_image'] = array($settings['default_image']); - } - else { - $settings['default_image'] = array(); - } - $field_config->set('settings', $settings); - $field_config->save(); - } - - } - } - - foreach (config_get_storage_names_with_prefix('field.instance.') as $config_name) { - $instance_config = config($config_name); - if ($instance_config->get('field_type') == 'image') { - $settings = $instance_config->get('settings'); - if (!is_array($settings['default_image'])) { - if (!empty($settings['default_image'])) { - $settings['default_image'] = array($settings['default_image']); - } - else { - $settings['default_image'] = array(); - } - $instance_config->set('settings', $settings); - $instance_config->save(); - } - } - } -} diff --git a/core/modules/image/image.module b/core/modules/image/image.module index a7696a6..addc388 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -1030,3 +1030,23 @@ 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) { + $instance = $type == 'field_instance'; + $instance = $instance && config('field.field.' . $entity->field_name)->get('type') == 'image'; + $field = $type == 'field_entity' && $entity->type == 'image'; + + if ($instance || $field) { + if (!empty($entity->settings['default_image'][0])) { + $entity->settings['default_image'] = $entity->settings['default_image'][0]; + } + else { + $entity->settings['default_image'] = 0; + } + } +}