1 image.module image_field_update_instance($instance, $prior_instance)

Implements hook_field_update_instance().

File

core/modules/image/image.module, line 446
Exposes global functionality for creating image styles.

Code

function image_field_update_instance($instance, $prior_instance) {
  // Only act on image fields.
  $field = field_read_field($instance['field_name']);
  if ($field['type'] != 'image') {
    return;
  }

  $uri_new = $instance['settings']['default_image'];
  $uri_old = $prior_instance['settings']['default_image'];

  // Delete the old file, if present.
  if ($uri_old && $uri_new != $uri_old) {
    file_unmanaged_delete($uri_old);
  }

  // If the upload destination changed, then move the file.
  if ($uri_new && (file_uri_scheme($uri_new) != $field['settings']['uri_scheme'])) {
    $directory = $field['settings']['uri_scheme'] . '://default_images/';
    file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
    file_move($uri_new, $directory . basename($uri_new));
  }
}